“if” considered harmful in ASP.NET MVC View (.aspx) files?

后端 未结 7 1193
孤城傲影
孤城傲影 2021-02-10 05:47

I remember seeing a blog (or something) that said you should not use <% if ... %> in .aspx files in ASP.NET MVC, but I can\'t remember what it said the alternative is. Can a

7条回答
  •  一整个雨季
    2021-02-10 05:58

    Basically what it means is that you shouldn't have huge if statements in your Views, your Controllers and ViewModels should be able to handle the logic. Example:

    <% if (ViewData["category"] == null { %> All Products <% } else { % > <%= ViewData["category"] %> <% } %>

    Should be:

    <%= Html.GetPageTitle(Model.Category) %>

提交回复
热议问题