From View you can send data in multiple ways. Here one can choose any one option to do that:
Option 1:
When if all model data needed then follow this way-
In View:
@using(Html.BeginForm())
{
//all model data
<input type=”submit” value=”SaveData” name=”command”>
}
In controller:
public ActionResult Index(Roster model)
Option 2:
In your form submission time, if only one input field data is needed then you can follow this way-
In View:
@using(Html.BeginForm())
{
<input type=”text” value=”demodata” name=”HidSaveType“>
<input type=”submit” value=”SaveData” name=”command”>
}
In controller:
public ActionResult Index(string HidSaveType)
Notice here “HidSaveType” is a name of input type text and must be keep in your form tag and its name same as the controller parameter name.
Option 3:
This option needed when all form data is needed. This is also important and usefull when you work with dynamic input field. Mention here again that the input field data come from view must be it need to keep in your form tag
In View:
@using(Html.BeginForm())
{
<input type=”text” value=”demodata”>
<input type=”submit” value=”SaveData” name=”command”>
}
In controller:
public ActionResult Index(FormCollection form)