Which solution is better and why?
It depends.
What are the advantages and disadvantages?
- HtmlHelper extension profiles:
- It will work no matter what viewing engine you use.
- This is a verified entity.
- It is transferred between applications
- HtmlHelper Custom Extension Disadvantages:
- It can become cumbersome to write a lot of HTML logic in C #
- Pros
@helper : - Against
@helper :
In fact, the fact is that @helper IMHO is completely useless. If you need the benefits that I mentioned about the HtmlHelper user extension, you can also create the HtmlHelper user extension.
And if you come across some of the flaws that I mentioned about the HtmlHelper user extension, you, well, use a partial view.
I only read that in MVC 3, when @helper is created globally in a separate .cshtml it is not possible to use other built-in html helpers.
It is not right. You could perfectly use other Html helpers. You just need to pass them as parameters:
@helper FooBar(HtmlHelper html) { feel free to use the html helper here }
and when consumed from a view:
@HelperName.FooBar(Html)
source share