LifeScript
LifeScript

Reputation: 1114

First day in AJAX in .NET MVC4, it doesn't work

Still trying to figure that out, here is my workflow:

  1. once submit been clicked, the jquery will send a post request to call the method
  2. method return a partial view
  3. display on <div id = "messageForm">...</div> part

below is the form view:

//SignUp.cshtml:
<div id ="messageForm">

@using (Ajax.BeginForm("SignUp", "MVP", new AjaxOptions
{

    Confirm = "Are you sure you want to send this message?",
    HttpMethod = "Post",                                 
    InsertionMode = InsertionMode.Replace,                                 
    LoadingElementId = "loading",                                 
    UpdateTargetId = "messageForm"
})) {

      @Html.AntiForgeryToken();
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>
            messageModel

        </legend>

         <p>
            <input type ="submit" value ="Send Message" />
        </p>

    </fieldset>

here is the controller:

//MVPController
       [HttpPost]
            public ActionResult SignUp(MVCView model){
                return PartialView("_ThankYou");

            }

public ActionResult SignUp(){
                return View();
            }

Here is the partial view in view folder:

ThankYou.cshtml:

    <h1>Thank you so much! We will contact you later</h1>

When testing it, I didn't see the confirm dialog and it redirect to the thank you page

Can anyone tell me why that happened?

Upvotes: 0

Views: 207

Answers (1)

Christian Phillips
Christian Phillips

Reputation: 18769

You have:

@using (Ajax.BeginForm("ThankYou", "MVP", new AjaxOptions

I think this should be:

@using (Ajax.BeginForm("SignUp", "MVP", new AjaxOptions

The first string is the Action name, and you only have SignUp in the controller.

Upvotes: 1

Related Questions