阻止Ajax.BeginForm在MVC 4中重置

时间:2013-09-03 05:02:01

标签: asp.net-mvc ajax.beginform

我创建了一个Ajax表单,如:

@using (Ajax.BeginForm("myaction", "mycontroller", new AjaxOptions
        {
            UpdateTargetId = "result",
            HttpMethod = "POST",
            OnSuccess = "success"
        }, new { @id = "myForm" }))
        {
            @Html.ValidationSummary(true)

            <div class="editor-label">
                @Html.LabelFor(model => model.autoadvertfilter.Manufacturer)
            </div>
            <div class="editor-field">
                @Html.DropDownListFor(model => model.autoadvertfilter.Manufacturer, (SelectList)ViewBag.Mfr, "--Select--")
                @Html.ValidationMessageFor(model => model.autoadvertfilter.Manufacturer)
            </div>

        <p>
            <input type="submit" value="Go" />
        </p>
        }

当我提交此表单时,它会重置。我希望这个表单即使在成功提交后也能保留这些值。任何建议将不胜感激。

1 个答案:

答案 0 :(得分:0)

您可以使用TempData在会话中存储值,就像在没有ajax的情况下对表单进行服务器验证时一样。

http://www.codeproject.com/Articles/476967/WhatplusisplusViewData-2cplusViewBagplusandplusTem