我有一个包含表单的页面(如下):
将我的ViewModel传递到控制器中是否是一种好的做法?如果不是,我该如何捕获表单中的所有数据?
谢谢!
@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>
}
}
正如您所看到的,此表单与“Process”控制器中的“GetResults”操作方法相关联。因此,当用户单击“提交”时,传递的对象应该是在表单中定义的对象,对吗?
这是我的“GetResults”操作方法:
public ActionResult GetResults(ProcessViewModel vm)
{
vm.NumberOfCapsules = 100;
List<Results> results = context.GetResults();
return View(results);
}
将我的ViewModel传递到控制器中是否是一种好的做法?如果不是,我该如何捕获表单中的所有数据?
谢谢!