I have a page that contains a form (below):
@using (Html.BeginForm("GetResults", "Process"))
{
@Html.ValidationSummary(true)
{
<div data-role="fieldcontain">
<label for="name">API #1:</label><br />
@Html.EditorFor(model => model.Active1.mg)
@Html.ValidationMessageFor(model => model.Active1.mg)
</div>
<div data-role="fieldcontain">
<label for="name">API #2:</label><br />
@Html.EditorFor(model => model.Active2.mg)
@Html.ValidationMessageFor(model => model.Active2.mg)
</div>
<div data-role="fieldcontain">
<label for="name">API #3:</label><br />
@Html.EditorFor(model => model.Active3.mg)
@Html.ValidationMessageFor(model => model.Active3.mg)
</div>
<div data-role="fieldcontain">
<label for="name">API #4:</label><br />
@Html.EditorFor(model => model.Active4.mg)
@Html.ValidationMessageFor(model => model.Active4.mg)
</div>
<div data-role="fieldcontain">
<label for="name">API #5:</label><br />
@Html.EditorFor(model => model.Active5.mg)
@Html.ValidationMessageFor(model => model.Active5.mg)
</div>
<div data-role="fieldcontain">
<label for="name">Key Active:</label><br />
@Html.EditorFor(model => model.KeyActive.mg)
@Html.ValidationMessageFor(model => model.KeyActive.mg)
</div>
<div data-role="fieldcontain">
<label for="name">Key Active Pack Stat:</label><br />
@Html.EditorFor(model => model.KeyActive.key_active_pack_stat)
@Html.ValidationMessageFor(model => model.KeyActive.key_active_pack_stat)
</div>
<div data-role="fieldcontain">
<label for="lble4m">E4M: </label>
<br />
@Html.DropDownList("ddle4m", new[] { new SelectListItem() { Text = "Off", Value = "False" }, new SelectListItem() { Text = "On", Value = "True" } }, new { data_role = "slider" })
</div>
<div data-role="fieldcontain">
<label for="lblk100m">K100M: </label>
<br />
@Html.DropDownList("ddlk100m", new[] { new SelectListItem() { Text = "Off", Value = "False" }, new SelectListItem() { Text = "On", Value = "True" } }, new { data_role = "slider" })
</div>
<div data-role="fieldcontain">
<label>Choose Filler:</label><br />
<fieldset data-role="controlgroup">
@foreach (var i in Model.Fillers)
{
<input type="radio" name="radio-choice" id="@i.pk" />
<label for="@i.pk">@i.name</label>
}
</fieldset>
</div>
<p>
<input type="submit" value="Create" />
</p>
}
}
As you can see, this form is tied to the “GetResults” action method inside of the “Process” controller. So consequently, when the user clicks “Submit”, the object that is passed SHOULD be the object defined in the form, right?
Here’s my “GetResults” action method:
public ActionResult GetResults(ProcessViewModel vm)
{
vm.NumberOfCapsules = 100;
List<Results> results = context.GetResults();
return View(results);
}
Is passing my ViewModel into my controller a good practice, and if not, how would I capture all of the data from the form?
Thanks..!
You sure posted a lot of code there. And then you ask a question. The answer to that question is: YES.