I have form collection accessed in action method ,but how to get the value of it .I tried like this
string value = collection[1];
but I am not getting the value .How can I access the value in action method.
I have form collection accessed in action method ,but how to get the value of it .I tried like this
string value = collection[1];
but I am not getting the value .How can I access the value in action method.
See your HTML file (or use Inspect Element) to see the name attribute in the input field. For instance if you have
<input type = "text" name = "YourName"/>
In the controller,
[HttpPost]
public ActionResult ActionName(FormCollection fc) /*Using FormCollection*/
{
string variable_name = fc["YourName"];
return View();
}
FormCollection is one way of retrieving view data in controller. Depending on the type of value in input, you can parse its non-string value to string in the Action method.