Alex Rivera | Logout

ASP.NET MVC: Razor @helper vs extension methods to HtmlHelper - which is preferred?

Asked 2011-06-08T22:05:15.077
9

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?

Edit
Report

1 Answer

9

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.

answered 2011-06-08T22:06:10.713

Your Answer