How to get html controls value in controller?

How to pass value from view to controller?

How to pass textbox value to controller in asp.net mvc?

I have a solution is below:

You just Check below example:

I typed below code in my view



@using (Html.BeginForm("Add", "Student",FormMethod.Post))
{
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td>
Studemt Name : <input id="studname" id="studname" type="text" />
</td>

</tr>

<tr>
<td>
<input type="submit" name="submit" value="Submit" />
</td>
</tr>

</table>
}

I typed below code in my controller.



[HttpPost]
public ActionResult Add(FormCollection collection)
{
string name = collection.Get("studname");
return View();
}

About the Author

avatar