InterviewSolution
| 1. |
What are HTML Helpers in MVC |
|
Answer» Html helper class helps when we WANT to show the PROPERTY of the modal class into the view we use HTML helper class also when we want the values from the HTML input method parameter into the modal property we use HtmlHelper, HtmlHelper class generates HTML elements using the model class OBJECT in razor view. Eg. <p> @Html.ActionLink(“Create New”,”Create”) </p>@Html is an object of HtmlHelper class. (We can access a server-side object in razor syntax by using @ symbol).it is a property which is included in the base class of razor view WebViewPage. ActionLink() and DisplayNameFor() is extension methods included in HtmlHelper class, HTML is a property that we inherit from the ViewPage base class. So, it's available in all of our views and it returns an instance of a type called HTML Helper. “HTML.BeginForm” writes an opening Form Tag. It also ensures that the method is going to be “Post” when the user clicks on the “Save” button. Html.Beginform is very helpful as it helps us in changing the Url and helps us in changing the methods, The Html.LabelFor HTML Helper creates the labels on the screen. If we entered something wrong then it will display the error using Html.ValidationMessageFor . There are lots of BENEFITS: It has overloaded methods to pre-populate the values (formatted, and safe for HTML) just like the ViewState. It allows you to override the rendering by providing your own DLL for changing the rendering (a sort of "Controller Adapter" type methodology). |
|