1

To edit a record, I'm opening a modal Kendo UI window populated with a partial view containing an AJAX enabled form:

@model MVC_ACME_Hardware.Models.BaseModel

<script type="text/javascript">
    $(function () {
        $("form").kendoValidator();
    });
</script>

@using (Ajax.BeginForm("EditProduct", new AjaxOptions { UpdateTargetId = "ProductDiv", OnSuccess = "SomeMethod" }))
{
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>EmployeeFTE</legend>

        @Html.HiddenFor(model => model.Products.Product_ID)

        <div class="editor-label">
            @Html.LabelFor(model => model.Products.Product_Name)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Products.Product_Name)
            @Html.ValidationMessageFor(model => model.Products.Product_Name)
        </div>

        <input type="submit" value="Save" class="myButton" />
    </fieldset>
}

When I run the form and click 'Save' on the popup, the form posts successfully but the post is not done via AJAX and my 'SomeMethod' onsuccess method is not being called. I've tried adding...

<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>

...on the partial view but it did not help. How can I get my form to submit using AJAX? I'm missing something obvious. Thanks!

4

2 に答える 2

0

MVC の控えめな検証と AJAX フォームの Ajax オプションを使用する場合は、これらのファイルを追加する必要があると思います。

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script> 
于 2013-09-19T08:33:23.633 に答える
0

このようなことを試してください(入力タイプに注意してください):

<input type="button" value="Save" class="myButton" id="btnSave" />

および $(document).ready() 内:

var validator = $(document.forms[0]).kendoValidator().data("kendoValidator");    
$("#btnSave").click(function(e) {     
              if (validator.validate()) {
                    var formContent = $(document.forms[0]).serialize();
                    var url = $(document.forms[0]).action;
                    $.post(url, formContent).done(function(data) {
                          $(document.body).append("<div class='savedRecordMessage'>success</div>");
                    });
               }
        });
于 2013-05-13T10:51:04.920 に答える