There are five way of passing from a form to MVC controller.
In Action method we can simply get any data posted from controls in a view by using Request.Form.
Example – Request.Form[“Control1Name”],Request.Form[“Control2Name”]
- Using FormCollection class.
Simply add a FormCollection object as parameter to action method. ModelBinder will populate the object with Form data.
Public ActionResultSaveCustomerData(FormCollection fc)
- We can also get posted data as Action method parameters.
Public ActionResultSaveCustomer(string TxtCustomerName,stringTxtAddress)
- We can also create an action method accepting a complex class object as parameter.
We call it model)
Public ActionResultSaveCustomer(Customer o)
Binding of posted form values and Customer object properties will be done by Model binder automatically.
- Using UpdateModel and TryUpdateModel method which is the most recommended one.
Customer o=new Customer();
Here are 50 MVC Interview questions with answer code project article. http://www.codeproject.com/Articles/556995/Model-view-controller-MVC-Interview-questions-and
We are thankful to questpond.com to provide this MVC Interview question with answer.
Also see the below MVC interview question with answer video on MVC asynch controller and thread starvation.