Reputation: 1786
I have a situation where I have a strongly typed View which is passed a ViewModel from a controller action. When the user submits the form in the view back to the controller I can get access to the values that have been set in the form via the properties of the View Model (all good so far). If my form contains other controls that are not bound via the view model can I quiz those values after the post. For example if I had a bunch of text boxes that are bound to strings in my View Model and a checkbox that doesn't form part of the data on that View Model can I get access to both on post back.
Hope that makes sense.
Cheers
Simon.
Upvotes: 3
Views: 6301
Reputation: 10694
You can access form fields by its name
from view
to controller
In View
<input type="text" name="fname"/>
In Controller
public ActionResult YourAction(Model model,string fname)
{
//Access fname here
}
If your want to access multiple values from view which are not binded to model you can use FormCollection
public ActionResult YourAction(Model model,FormCollection form)
{
//Access fname here like below
var firstName=form["fname"];
}
Upvotes: 6