jeudi 2 novembre 2017

ASP.NET MVC Razor is printing local inline if statement result when it should only set local Razor variable

I have some Razor code which uses a custom attribute to basically see if I should display a link. I'm using two local Razor variables (Edit and Delete) so I don't have to call this function multiple times on the page.

@{bool Edit = false;}
@{bool Delete = false;}

@(User.IsAuthorized("EmployeePhotos/Employees/Edit") ? Edit = true : Edit = false)
@(User.IsAuthorized("EmployeePhotos/Employees/Delete") ? Delete = true : Delete = false)

While the inline if statement is setting the local Razor variables correctly... it's printing True True on the page itself.

It doesn't do this with a normal if statement:

@if (User.IsAuthorized("EmployeePhotos/Employees/Edit"))
{
    Edit = true;
}

Why is the one-liner if statement printing my function result but the normal if statement isn't?

Aucun commentaire:

Enregistrer un commentaire