3

我有一个包含表单的页面(如下):

@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 传递给我的控制器是一个好习惯,如果不是,我将如何从表单中捕获所有数据?

谢谢..!

4

1 回答 1

3

你肯定在那里发布了很多代码。然后你问一个问题。这个问题的答案是:是的。

于 2013-02-21T01:00:00.070 回答