Reputation: 1
I have used this characteristic of MVC, where you have a control in a view, lets say a checkbox:
@Html.CheckBox("isNewlyEnrolled", true)
and in the controller you declare a parameter with the same name:
[HttpPost]
public ActionResult SearchExpressionTester(string isNewlyEnrolled, SearchExpressionModel SearchExpression)
Then you can use the value of the checkbox in the controller.
Is this process of the controller receiving the string value that I don't fully understand. I know there's no need to add a new parameter to the model.
I can't find information about how this Works in any MVC book, article and so on. What is the name of this technique for passing parameters to the controler?
Upvotes: 0
Views: 61
Reputation: 3230
Using HTML Helpers, that's all. You could also do <input type="checkbox" name="isNewlyEnrolled" checked="checked">
and the result would be the same.
Basically, you are using built-in functions to generate HTML elements.
List of most used HTML helpers:
Usage:
@using (Html.BeginForm())
{
}
Produces:
<form action="..." action="post">
Usage:
@Html.Label("Name")
Produces:
<label for="Name">
Name
</lable>
Usage:
@Html.TextBox("Name", null, null)
Produces:
<input id="Name" name="Name" type="text" value="" />
Usage:
@Html.TextArea("Description", null, null)
Produces:
<textarea id="Description" name="Description" rows="2" cols="20"></textarea>
Usage:
@Html.Password("Password")
Produces:
<input id="Password" name="Password" type="password" value="" />
Usage:
@Html.DropDownList("StudentGender", new SelectList(Enum.GetValues(typeof(Gender))), "Select Gender", null)
Produces:
<select id="StudentGender" name="StudentGender">
<option>Select Gender</option>
<option>Male</option>
<option>Female</option>
</select>
Usage:
@Html.RadioButton("Gender", "Male")
Produces:
<input checked="checked" id="Gender" name="Gender" type="radio" value="Male" />
Usage:
@Html.Hidden("StudentId")
Produces:
<input id="StudentId" name="StudentId" type="hidden" value="1" />
Go here to learn more are about model binding in ASP.NET.
Upvotes: 2