帶有 HTML 輸出的標準 HTML 幫助程式

Html.TextBox()

  • @Html.TextBox("Name", null, new { @class = "form-control" })
    output: <input class="form-control" id="Name"name="Name"type="text"value=""/>
  • @Html.TextBox("Name", "Stack Overflow", new { @class = "form-control" })
    output: <input class="form-control" id="Name"name="Name"type="text" value="Stack Overflow"/>

Html.TextArea()

  • @Html.TextArea("Notes", null, new { @class = "form-control" })
    output: <textarea class="form-control" id="Notes" name="Notes" rows="2" cols="20"></textarea>
  • @Html.TextArea("Notes", "Please enter Notes", new { @class = "form-control" })
    output: <textarea class="form-control" id="Notes" name="Notes" rows="2" cols="20" >Please enter Notes</textarea>

Html.Label()

  • @Html.Label("Name","FirstName")
    output: <label for="Name"> FirstName </label>
  • @Html.Label("Name", "FirstName", new { @class = "NameClass" })
    output: <label for="Name" class="NameClass">FirstName</label>

Html.Hidden()

  • @Html.Hidden("Name", "Value")
    output: <input id="Name" name="Name" type="hidden" value="Value" />

Html.CheckBox()

  • @Html.CheckBox("isStudent", true)
    output: <input checked="checked" id="isStudent" name="isStudent" type="checkbox" value="true" />

Html.Password()

  • @Html.Password("StudentPassword")
    output: <input id="StudentPassword" name="StudentPassword" type="password" value="" />