HTML Helper in Strongly Typed View – Session 30

HTML Helper in ASPNET Core Part 3 - Session30-min

During this session of ASP.NET 5.0 training, we use HTML Helpers in Strongly Typed View. In session 28 and session 29 we created a form with Label, TextBox, DropDownList and TextArea HTML Helper while we have not use Strongly Typed View. Now, We will design another form with another type of these Helpers in a Strongly Typed View.

Create Form with Html Helper in Strongly Typed View.

In this session, we want to create another Form same as the form that we designed in session 29, but this time we use strongly typed view. Thus, first we need to add another property to the CreateCostViewModel that store the SelectListItems.

Then, inside CostController we create an Action Method for the new Form.

Next, we create the SelectListItem that we want to use in the Drop Down List.

Now, we need to create an object of the ViewModel to store default values and the SelectListItems to be passed to the View.

Then, we need to pass this object to the View().

After the above steps, we need to create a View inside Views/Cost to created Action Method. Also, we should use @model directive and bind it to the ViewModel

Finally, we can create the form with LabelFor, TextBoxFor, TextAreaFor and DropDownListFor in the created strongly typed view.

As you can see in above code, we don’t use “Expression” and “Default Values” in the helpers and just we bind each helper to the respective property of the ViewModel with Lambda Expression (for example m=>m.comment)

Also, we can use Html Attributes in the helpers and you can see in below piece of code.

If you need more details, watch this session video. Also, for being updated about our coming sessions, follow us on Instagram, Facebook, Telegram or YouTube. Also you can have access to list of all sessions HERE.

You can download this Session Slides form HERE

0.00 avg. rating (0% score) - 0 votes

Tags

0 0 votes
Article Rating
guest

0 Comments
Inline Feedbacks
View all comments