OnSuccess无法正常工作

OnSuccess无法正常工作

本文介绍了Ajax.OnSuccess无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我的表格有问题!当我发布它时,'Account_Create_OnSuccess'(我自己的jQuery函数)没有被触发。



我该怎么办?



Hi everybody,

I have a problem on my form! when I post it, the 'Account_Create_OnSuccess' (my own jQuery function) is not firing.

What should I do?

@using (Ajax.BeginForm("Create", "Account", new AjaxOptions
                                            {
                                                HttpMethod = "POST",
                                                OnSuccess = "Account_Create_OnSuccess"
                                            }))
{
    <div class="field-display">First Name:</div>
    <div class="field-editor">@Html.EditorFor(model => model.FirstName)</div>

    <br />

    <div class="field-display">Last Name:</div>
    <div class="field-editor">@Html.EditorFor(model => model.LastName)</div>

    <br />

    <div class="field-display">EMail:</div>
    <div class="field-editor">@Html.EditorFor(model => model.EMail)</div>

    <br />

    <div class="field-display">Password:</div>
    <div class="field-editor">@Html.PasswordFor(model => model.Password)</div>

    <br />

    <div class="field-display">Telephone:</div>
    <div class="field-editor">@Html.EditorFor(model => model.Tellphone)</div>

    <br />

    <div class="field-display">Cellphone:</div>
    <div class="field-editor">@Html.EditorFor(model => model.Cellphone)</div>

    <br />

    <div class="field-display"> </div>
    <div class="field-editor">
        <input type="submit" value="Submit" />
    </div>
}







[HttpPost]
        public ActionResult Create(Account account)
        {
            this.Database.Accounts.Add(account);
            this.Database.SaveChanges();

            return Json(new
                        {
                            Result = true,
                            Message = "Insert Successfully."
                        }, JsonRequestBehavior.AllowGet);
        }







function Account_Create_OnSuccess(data) {
    if (!data.Result) {
        MessageBox('Error!', data.Message); // my own MessageBox
        return;
    } else if (data.Result == true) {
        MessageBox('Success', data.Message); // my own MessageBox
    }
}

推荐答案




这篇关于Ajax.OnSuccess无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 07:33