ASP.NET MVC:剃刀@helper VS扩展方法的HtmlHelper - 这是preferred? [英] ASP.NET MVC: Razor @helper vs extension methods to HtmlHelper - which is preferred?

查看:125
本文介绍了ASP.NET MVC:剃刀@helper VS扩展方法的HtmlHelper - 这是preferred?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ASP.NET MVC中的Razor视图引擎支持@helper定义小帮手方法。看来你可以做很多通过添加扩展方法的HtmlHelper相同。在什么情况下是它最好使用的呢?

The Razor view engine in ASP.NET MVC supports @helper to define little helper methods. It seems you can do much the same by adding extension methods to HtmlHelper. In what situations is it best to use each?

推荐答案

主观的问题,所以这里是我的主观和片面的答案:当帮手code包括C#code量使用自定义的HtmlHelper时,它的主标记你可以使用 @helper 。但假设,当你有标记,你可以使用部分像 @ Html.Partial(_富,SomeModel)或编辑/像显示模板@ Html.EditorFor(X => x.Foo) @helper 不真的有什么实际用途。我个人从来没有使用 @helper 顺便说一句,我从来没有推荐它的使用情况,人我已经咨询。

Subjective question, so here's my subjective and biased answer: When the helper code involves amounts of C# code use a custom HtmlHelper and when it's primary markup you could use @helper. But assuming that when you have markup you could use a partial like @Html.Partial("_foo", SomeModel) or an editor/display templates like @Html.EditorFor(x => x.Foo), the @helper doesn't really have any practical use. Personally I've never used @helper by the way, and I've never recommended it's usage to people I've been consulting.

这篇关于ASP.NET MVC:剃刀@helper VS扩展方法的HtmlHelper - 这是preferred?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆