Click here to Skip to main content
15,888,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?

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


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

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


XML
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
    }
}
Posted
Comments
Mehul M Thakkar 16-Jul-13 9:53am    
did you try with OnFailure? check there is any error.
Saeid Mirzaei 18-Jul-13 1:26am    
Thanks for reply Mehul, yes I did but it's not firing too!

You should include a 'jquery.unobtrusive-ajax.js' file in your page.

regards.
 
Share this answer
 
Thanks Navid,

It works correctly for me.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900