Introduce: An html helper is a method that is used to render html content in a view.html helper are completed as extension method. “@Html” is a HtmlHelper and “ActionLink” is a one extension method for HtmlHelper. HtmlHelper decrease your coding.
List of HtmlHelper methods and Html content :
HtmlHelper |
Html Contant |
@Html.ActionLink(“Index”,”Index”,”Home”) |
<a href=”Home/Index”>Index</a> |
@Html.Label |
<label for=”Username”>Username</label> |
@Html.TextBox(“Username”) |
<Index type=”text” name=”Username” id=”Username” value=””/> |
@Html.Password(“Password”) |
<input type=”Password” name=”Password” id=”Password”> |
@Html.RadioButton(“Gender”,”Male”) |
<input type=”radio” value=”Male” name=”Gender” id=”Gender”/> |
@Html.DropDownList(“profession”,new SelectList(ViewBag.profession, “value”,”text”)) |
<select name=”profession” id=”profession”><option value=”student”>student</option><option value=”Employed”> Employed</option></select> |
@Html.TextArea(“message”) |
<textarea name=”message” id=”message”></textarea> |
@Html.CheckBox(“IAgree”) |
<input type=”checkbox” name=”IAgree” id=”IAgree/>” |
@Html.Hidden(“UserId”) |
<Input type=”hidden” name=”UserId” id=”UserId” value=””> |
create view using html helpers :
Step : 1
Add view “view name like as Index”
Step : 2
Example :1 write simple Html code for inputbox.
<Index type=”text” name=”Username” id=”Username” value=””/>
@Html.TextBox(“Username”)
Example :2 Now create a RegisterForm use htmlhelper.
step:1
Index.cshtml
<br /><br /><br />
@using(Html.BeginForm())
{
<form>
<ul>
<li>
@Html.Label("UserId")
@Html.Hidden("UserId")
</li>
<li>
@Html.Label("Username")
@Html.TextBox("Username")
</li>
<li>
@Html.Label("Passowrd")
@Html.Password("Password")
</li>
<li>
@Html.Label("Gender")
@Html.RadioButton("Gender","Male") Male
@Html.RadioButton("Gender", "Female") Female
</li>
<li>
@Html.Label("Profession")
@Html.DropDownList("Profession",new SelectList(ViewBag.Profession,"Text","Value"))
</li>
<li>
@Html.Label("I Agree")
@Html.CheckBox("IAgree")
</li>
<li>
@Html.Label("About yourself")
@Html.TextArea("AboutYourSelf")
</li>
</ul>
<button>Submit</button>
</form>
}
step:2 Write this code in your Controller for DropDownList [if you don't understand it,you can see the video].
HtmlHelperController.cs
public ActionResult Index()
{
List<SelectListItem> Item = new List<SelectListItem>();
Item.Add(new SelectListItem { Text = "Student", Value = "Student", Selected = false });
Item.Add(new SelectListItem { Text = "Employee", Value = "Employee", Selected = false });
ViewBag.Profession = Item;
return View();
}
Now run the project.
Related articles
MVC 5 Master Details Using Jquery Ajax | Entity Framework
MVC 5 Master Details Using Jquery Ajax | Entity Framework
Crystal Report Demo | Source Code Link
Crystal Report Demo | Source Code Link
CRUD Operations In MVC Using Jquery Ajax | Part-2 Create PopUp Modal With Registration Form
CRUD Operations In MVC Using Jquery Ajax | Part-2 Create PopUp Modal With Registration Form
CRUD Operation In MVC Using Jquery Ajax | Part-1 Retrieve Database Data & Show In A View
CRUD Operation In MVC Using Jquery Ajax | Part-1 Retrieve Database Data & Show In A View
Dynamically Loading Content With Jquery Ajax | ASP.NET MVC
Dynamically Loading Content With Jquery Ajax | ASP.NET MVC
Autocomplete Textbox In MVC | With Database | Jquery Ajax ⋆⋆⋆
Autocomplete Textbox In MVC | With Database | Jquery Ajax ⋆⋆⋆
How To Check Username Already Exist In Database In Asp.Net MVC | Jquery,Ajax
How To Check Username Already Exist In Database In Asp.Net MVC | Jquery,Ajax
How To Create Cascading Dropdownlist In Asp.Net MVC | Using Jquery Ajax
How To Create Cascading Dropdownlist In Asp.Net MVC | Using Jquery Ajax
How to export database data in excel file using ASP.NET MVC
How to export database data in excel file using ASP.NET MVC
How to upload image in database and displaying it using ASP.NET MVC | jquery Ajax
How to upload image in database and displaying it using ASP.NET MVC | jquery Ajax