Html.Partial and Html.RenderPartial in MVC

The Partial helper renders a partial view into a string. Typically, a partial view contains reusable markup you want to render from inside multiple different views. Partial has four overloads: public void Partial(string partialViewName); public void Partial(string partialViewName, object model); public void Partial(string partialViewName, ViewDataDictionary viewData); public void Partial(string partialViewName,… Continue reading

Html.CheckBox in MVC

The CheckBox helper is unique because it renders two input elements. Take the following code, for example: @Html.CheckBox(“IsDiscounted”) This code produces the following HTML: <input id=”IsDiscounted” name=”IsDiscounted” type=”checkbox” value=”true” /> <input name=”IsDiscounted” type=”hidden” value=”false” /> You are probably wondering why the helper renders a hidden input in addition to the… Continue reading

Html.Password in MVC

The Html.Password helper renders a password field. It’s much like the TextBox helper, except that it does not retain the posted value, and it uses a password mask. The following code: @Html.Password(“UserPassword”) results in: <input id=”UserPassword” name=”UserPassword” type=”password” value=”” /> The strongly typed syntax for Html.Password, as you’d expect, is… Continue reading

Html.Hidden in MVC

The Html.Hidden helper renders a hidden input. For example, the following code: @Html.Hidden(“wizardStep”, “1”) results in: <input id=”wizardStep” name=”wizardStep” type=”hidden” value=”1″ /> The strongly typed version of this helper is Html.HiddenFor. Assuming your model had a WizardStep property, you would use it as follows: @Html.HiddenFor(m => m.WizardStep)

Html.DropDownList and Html.ListBox in MVC

Both the DropDownList and ListBox helpers return a <select /> element. DropDownList allows single item selection, whereas ListBox allows for multiple item selection (by setting the multiple attribute to multiple in the rendered markup). Typically, a select element serves two purposes: To show a list of possible options To show… Continue reading