In MVC there is no server side control, we have to use HTML HELPER.

There are the following types of HTML HELPERS:

  1. Non Strongly Typed Html Helper
  2. Strongly Typed Html Helper
  3. Custom Helper

1. Non Strongly Typed Html Helper

Html.TextBox is not strongly typed and it do not require a strongly typed view.

It is not bounded with Model and non-strongly typed html helper is independent of model kind of things.

2. Strongly Typed Html Helper

Html.TextBoxFor is strongly typed and it require a strongly typed view. It is bounded with Model property.

3. Custom Helper: You can design your own helper with.

Through the following charts, I had indirectly designed a form control for FRIEND entry for NON STRONGLY TYPED.

CONTROL NAME NON STRONGLY TYPED HTML HELPERS
CheckBox @Html.CheckBox(“chkMarried”,0)

HTML RENDER:

<input id="chkMarried" name="chkMarried" type="checkbox" value="true" /><input name="chkMarried" type="hidden" value="false" />
Drop Down List @Html.DropDownList(“ddlEducationLevel”, new SelectList(new[]{“SSC”,”HSC”,”Graducation”,”Post Graducation”}))

HTML RENDER:

<select id="ddlEducationLevel" name="ddlEducationLevel"><option>SSC</option>
<option>HSC</option>
<option>Graduation</option>
<option>Post Graducation</option>
</select>
HiddenField @Html.Hidden(“hdnDateTime”,@DateTIme.Now.Tostring())

HTML RENDER:

<input id="hdnDateTime" name="hdnDateTime" type="hidden" value="01/09/16 20:47:46" />
Label @Html.Label(“lblFriendName”,”Friend Name”)

HTML RENDER:

<label for="lblFriendName">Name</label>
ListBox @{
var items = new List<SelectListItem>{
new SelectListItem {Value = "1", Text = "Visual Foxpro"},
new SelectListItem {Value = "2", Text = "Visual Basic"},
new SelectListItem {Value = "3", Text = "C#", Selected = true},
new SelectListItem {Value = "4", Text = "Javascript", Selected = true},
new SelectListItem {Value = "5", Text = "Java"}
};
}
@Html.ListBox(“lstLanguageKnow”, items)

HTML RENDER:

<select id="lstLanguageKnow" multiple="multiple" name="lstLanguageKnow"><option value="1">Visual Foxpro</option>
<option value="2">Visual Basic</option>
<option selected="selected" value="3">C#</option>
<option selected="selected" value="4">Javascript</option>
<option value="5">Java</option>
</select>
Password @Html.Password(“txtPassword”)

HTML RENDER:

<input id="txtPassword" name="txtPassword" type="password" />
Radio Button Male: @Html.RadioButton(“rbGender”,”Male”)
Female:@Html.RadioButton(“rbGender”,”Female”)

HTML RENDER:

Male: <input id="rbGender" name="rbGender" type="radio" value="Male" />
Female: <input id="rbGender" name="rbGender" type="radio" value="Female" />
TextArea @Html.TextArea(“txtAddress”)

HTML RENDER:

<textarea cols="20" id="txtAddress" name="txtAddress" rows="2">
</textarea>
TextBox @Html.TextBox(“txtName”)

HTML RENDER:

<input id="txtName" name="txtName" placeholder="Enter Friend Name" type="text" value="" />

Output

Run

VIEW CODE: new.cshtml

  1. @{
  2. ViewBag.Title = "New";
  3. Layout = "~/Views/Shared/_Layout.cshtml";
  4. }
  5. <h2>New Friend</h2>
  6. <form method="post">
  7. <table>
  8. <tr>
  9. <td>
  10. @Html.Label("lblName", "Name")
  11. @Html.Hidden("hdnDateTime", @DateTime.Now.ToString())
  12. </td>
  13. <td>
  14. @Html.TextBox("txtName", "", new { placeholder = "Enter Friend Name" })
  15. </td>
  16. </tr>
  17. <tr>
  18. <td>
  19. @Html.Label("lblAddress", "Address")
  20. </td>
  21. <td>
  22. @*@Html.TextArea("txtAddress", "", 4, 30, new {placeholder="Enter Your Address"})*@
  23. @Html.TextArea("txtAddress")
  24. </td>
  25. </tr>
  26. <tr>
  27. <td>
  28. @Html.Label("lblPlace", "Place")
  29. </td>
  30. <td>
  31. @Html.TextBox("txtPlace")
  32. </td>
  33. </tr>
  34. <tr>
  35. <td>
  36. @Html.Label("lblMobile", "Mobile Number")
  37. </td>
  38. <td>
  39. @Html.TextBox("txtMobile")
  40. </td>
  41. </tr>
  42. <tr>
  43. <td>
  44. @Html.Label("lblGender", "Gender")
  45. </td>
  46. <td>
  47. Male: @Html.RadioButton("rbGender", "Male", new {value="Male"})
  48. Female: @Html.RadioButton("rbGender", "Female",new {value="Female"})
  49. </td>
  50. </tr>
  51. <tr>
  52. <td>
  53. @Html.Label("lblMarital", "Is Married")
  54. </td>
  55. <td>
  56. @Html.CheckBox("chkMarried", 0)
  57. </td>
  58. </tr>
  59. <tr>
  60. <td>
  61. @Html.Label("lblEducationLevel", "Education Level")
  62. </td>
  63. <td>
  64. @Html.DropDownList("ddlEducationLevel", new SelectList(new[] { "SSC", "HSC", "Graduation", "Post Graducation" }))
  65. </td>
  66. </tr>
  67. <tr>
  68. <td>
  69. @Html.Label("lblLanguageKnown", "Language Known")
  70. </td>
  71. <td>
  72. @{
  73. var items = new List<SelectListItem>{
  74. new SelectListItem {Value = "1", Text = "Visual Foxpro"},
  75. new SelectListItem {Value = "2", Text = "Visual Basic"},
  76. new SelectListItem {Value = "3", Text = "C#", Selected = true},
  77. new SelectListItem {Value = "4", Text = "Javascript", Selected = true},
  78. new SelectListItem {Value = "5", Text = "Java"}
  79. };
  80. }
  81. @Html.ListBox("lstLanguageKnow", items)
  82. </td>
  83. </tr>
  84. <tr>
  85. <td>
  86. @Html.Label("lblPassword", "Password")
  87. </td>
  88. <td>
  89. @Html.Password("txtPassword")
  90. </td>
  91. </tr>
  92. </table>
  93. <br />
  94. <input type="submit" id="submit" value="Submit" />
  95. </form>
In the next article, I will explain about Strongly Typed HTML HELPER.