English 中文(简体)
POST a Ajax form from a Kendo UIdow
原标题:POST an Ajax form from a Kendo UI window

为了保存记录,Im打开了Kendo UI窗口,其部分观点包括日本宇宙航空和宇宙航空研究开发机构:

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

......根据部分观点,但并不帮助。 我如何利用AJAX提交表格? 我没有一点明显的东西。 感谢!

问题回答

尝试这样的东西(保留投入类型):

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

(文件)

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>");
                    });
               }
        });

我认为,如果你想利用日本宇宙航空研究开发机构表格中的MVC和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> 




相关问题
Return int from MVC Action with Ajax.BeginForm

Whats the simplest way of just returning an int from an Ajax MVC Action call? I am currently trying: public ContentResult Create(MyModel model) { return Content("1"); } using (Ajax.BeginForm("...

Ajax comments form in ASP.NET MVC2, howto?

I ve been playing around with different aspects of MVC for some time now, and I ve reached a situation where I m not sure what would be the best way to solve a problem. I m hoping that the SO ...

asp.net mvc Ajax.BeginForm

I m having some difficulties with Ajax.BeginForm I have something like this in a view <% using (Ajax.BeginForm("ActionName", null , null, new { id = "FormName" })) {%> <input ...

How do I prevent Ajax.BeginForm from loading a new page?

I have an Ajax form with a single input and a button. On submit, the form should only post the entered value to an action method. My form is correctly posting to the User controller s Log method but ...

热门标签