Prevent Ajax.BeginForm from reset in MVC 4

562 Views Asked by At

I have created an Ajax Form like:

@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>
        }

When I submit this form, it resets. I want this form to keep the values even after successful submission. Any suggestions would be appreciated.

1

There are 1 best solutions below

0
On BEST ANSWER

You can use TempData to store the values in session, just as you do when you are doing server validation of the form without ajax.

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