Reputation: 8054
I have an AJAX form defined in Razor, like so:
using (Ajax.BeginForm("SaveProfile", "Settings",
new AjaxOptions
{
HttpMethod = "Post",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "result"
}))
{
...
...
The rest of the form is very basic. A couple of textboxes and a submit button.
Here's the controller action:
[HttpGet]
public ActionResult SaveProfile(int AccountID, string DisplayName, string Email)
{
string message = "Changes saved successfully.";
var user = db.LoginUsers
.Where(m => m.ID == AccountID)
.First();
if (user != null)
{
user.DisplayName = DisplayName;
user.Email = Email;
db.SaveChanges();
}
else
message = "Error. Changes were not saved.";
return PartialView("_Saved", message);
}
And here's the Partial View, "_Saved"
:
@model string
@Model
As you can see, it's an extremely basic process. The only issue is that it redirects the page instead of updating my target. I simply cannot figure out what's going wrong.
Upvotes: 1
Views: 171
Reputation: 8054
Apparently my jqueryval
bundle was not being rendered in my _Layout
. I assumed since it was a default feature of MVC, it would have done so. Such is not the case.
Be wary of which bundles are being rendered in your layout!
Upvotes: 1