Reputation: 400
I'm having a problem with using an Ajax form in MVC. Out of no where I am getting the following error:
POST http://localhost:50778/Evaluation/Setup/[object%20NodeList] 404 (Not Found)
It seems to not be adding the action or calling any simple validation. On oter pages it seems to work. i have stripped everything down the the basics below and it still doesn't work. Any ideas?
Edited: As a workaround i'm using jquery to submit the form but i really don't think i need to be doing that.
<div id="form-message"></div>
@{Ajax.BeginForm("UpdateEvaluation", "Setup", new AjaxOptions { UpdateTargetId = "form-message", InsertionMode = InsertionMode.Replace}, new { @id = "evaluation-setup" });}
@Html.HiddenFor(model => model.fk_baa)
@Html.HiddenFor(model => model.lock_setup)
<div class="form-actions">
<p><b>Note</b>: There is no spell check on this site. You may wish to create text in Word or another word processor and then copy-and-paste into the system. </p>
<button name="action" type="submit" value="save" class="btn btn-primary">Save</button>
<button id="apply-lock" name="action" type="submit" class="btn btn-success exempt" value="lock"><span class="ico fa"></span> Lock Setup</button>
</div>
@{Html.EndForm();}
Here is my action
[HttpPost]
public ActionResult UpdateEvaluation(SetupEvaluationModel model, string action)
{
var valid = ModelState.IsValid;
if (action.ToUpper().Equals("LOCK"))
{
return View("_Validation", model.Save(true));
}
else
{
return View("_Validation", model.Save());
}
}
Upvotes: 3
Views: 3904
Reputation: 14250
Rename String action
to a different name in your action signature. You'll have to rename your button names as well. With the code you have now the jquery.unobtrusive-ajax.js submit handler is trying to route to a button object instead of the correct string url route.
Upvotes: 4