Creating Forms using HTML Helpers

Lot of works to do? There comes HTML Helpers which able to help us with the problems. It's can be used only with .NET MVC framework.

The syntax looked like this. Put it in Add.cshtml class.

@using (Html.BeginForm())
{

}

Then, copy all of the form markup codes into the bracket excluding the <form method = "post">

Change all of the HTML tags.

// before

<label for="Date" class="control-label">Date</label>
<input type="text" id="Date" name="Date"
       class="form-control" value="@ViewBag.Date" />

// after
@Html.Label("Date", new { @class = "control-label"})
@Html.TextBox("Date", null, new { @class = "form-control"})

 <div class="form-group">
  @Html.Label("Notes", new { @class = "control-label" })
  @Html.TextArea("Notes", null, 14, 20, new { @class = "form-control" })
</div>

Then, we can erase the ViewBag code in AddPost function.

results matching ""

    No results matching ""