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

2020-06-05 07:54发布

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 anyone remember seeing this and point me to it?

7条回答
做自己的国王
2楼-- · 2020-06-05 08:25

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.

查看更多
登录 后发表回答