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

后端 未结 7 1210
孤城傲影
孤城傲影 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 06:17

    I think what you're referring to is a post by Rob Conery, where he mentions a rule he uses:

    If there's an if, make a helper

    So to answer your question, the idea is that if you find yourself needing to use if in your View, you should consider adding a helper extension method to render that part of your View instead.

提交回复
热议问题