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?
相关问题
- MVC-Routing,Why i can not ignore defaults,The matc
- parameters in routing do not work MVC 3
- There is no ViewData item with the key 'taskTy
- TextBoxFor decimal
- Install ASP.NET 5.0 version of System.ServiceModel
相关文章
- How to get a list of connected clients on SignalR
- How do you redirect to the calling page in ASP.NET
- Change color of bars depending on value in Highcha
- The program '[4432] iisexpress.exe' has ex
- ASP.Net MVC 4 Bundles
- How to get server path of physical path ?
- Cannot implicitly convert Web.Http.Results.JsonRes
- entity type has no key defined - Code first
Yes, that's true, though the @helpers seem a bit easier to work with if there's a good chunk of markup that's included--Html extensions and more extensive markup don't go that well together, IMO.
On the other hand, @helpers can't be unit tested like Html extensions.
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.