Razor and if statement
-
14-07-2021 - |
Pergunta
I'm using MS Razor in MVC 3 C#, I need to display some text "hello" within the IF statement. At the moment I receive an error. Any idea how to solve it?
EDIT: syntax error
@if(Model.IsCustomEvent)
{
@Html.ActionLink("Edit", "Edit", new { id=Model.EventTitle }) hello
}
Solução
you need to put :
before hello
@if(Model.IsCustomEvent)
{
@Html.ActionLink("Edit", "Edit", new { id=Model.EventTitle }) @:hello
}
Outras dicas
Use the @:
symbol for including literals
@if(Model.IsCustomEvent)
{
@Html.ActionLink("Edit", "Edit", new { id=Model.EventTitle })
@:hello
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow