1

Feel like I'm missing something simple here - When I submit this form it takes me to a white page with my encoded JSON model, rather than staying on the page I was on.

Form in a partial view, loaded on every page:

@using (Ajax.BeginForm("Inquiry", "Home", new AjaxOptions { HttpMethod = "POST", OnSuccess = "success" }))

And my actions:

    public ActionResult Inquiry()
    {
        return PartialView("_Inquiry",new Inquiry());
    }

    [HttpPost]
    public JsonResult Inquiry(Inquiry model)
    {
        if (ModelState.IsValid)
        {
            db.Inquiries.Add(model);
            db.SaveChanges();
        }
        return Json(model);
    }

1 Answer 1

4

Make sure you have referenced the following script in your page:

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

It is what makes the Ajax.* helpers work.

Sign up to request clarification or add additional context in comments.

3 Comments

I totally did! ...before my jQuery reference. Tired programming is a bad idea. Thank you, will accept as answer in the morning (stupid lockout)
Yeap, it should be added after jquery.
How to make that submit page blank to add another record( once one record is submitted)???

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.