Why do we use HTML helper in ASP.NET MVC?

前端 未结 2 1665
我寻月下人不归
我寻月下人不归 2021-01-04 01:24

Are there any good thing, best practice or profit we have after using the HTML helper in an ASP.NET MVC project?

When I am trying to use them I found that I lose the

2条回答
  •  无人及你
    2021-01-04 01:46

    You use HTML helpers to encapsulate some small HTML fragments which are repeated all over your pages. And to avoid writing those HTML snippets all over again you use helpers.

    They are very useful, especially when dealing with things like URLs because instead of hardcoding your links helpers take advantage of routing the definition on your server and by simply changing those routes the whole site URLs' change without ever touching any single HTML page.

    Another scenario where HTML helpers are useful is for generating form input fields. In this case they automatically could handle values when posting back and show associated validation messages. Can you imagine the spaghetti code you would have to write in your views if there weren't HTML helpers?

提交回复
热议问题