strongly typed html helpers in asp.net mvc razor - Tutorial

For Consultation : +91 9887575540

Stay Connected :

Strongly typed html helpers are introduced in MVC 2. In this kind of helpers we can generate html markup or view using model properties and lambda expression. These methods use a “Html.HelperNameFor()” naming convention. for example we have created model property like public string username{get;set;} We can create text box for username property in following way


HTML Element Helpers:

  • Html.TextBoxFor()
  • Html.TextAreaFor()
  • Html.DropDownListFor()
  • Html.CheckboxFor()
  • Html.RadioButtonFor()
  • Html.ListBoxFor()
  • Html.PasswordFor()
  • Html.HiddenFor()
  • Html.LabelFor()

Lets take an example where we are creating a registration form and going to show filled values on the same view.

Step1. Open VisualStudio=>Create New Project->Select Web in Visual C#->Asp.net web application->Select Empty and check MVC Checkbox

Step 2: Create a model “Employee.cs”

Step3: Create New Controller “Student”

Step 4: CReate new action strongly.

Step 5: Add View and pass model reference into newly created view.

In above code I created a simple registration form where I have taken dropdown and listbox also.I listbox we are taking hobbies from user and user can select multiple properties.

if block(if (@ViewBag.EmployeeId != null)) will work only after data submitted by end user and it is showing the filled values.

Step 6 : Now Write following code into student controller.

Now run and execute above code .



ASP.NET Core 2.0 Online Training

ASP.NET Core 2.0 Online Training

Select your currency