ASP.NET MVC AJAX value not displaying
- by mazhar kaunain baig
View:
function success(arg) {
var obj = arg.get_response().get_object();
if (obj.ErrorMessage === '') {
var answer = document.createElement('div');
answer.appendChild(document.createTextNode(obj.Answer));
document.getElementById('answers').appendChild(answer);
} else {
document.getElementById('errors').innerHTML = obj.ErrorMessage;
}
}
<% using (Ajax.BeginForm("EditOrganizationMeta", "Organization", new AjaxOptions { HttpMethod = "POST", OnSuccess = "success" })) { %>
<input type="submit" name="button<%=OrganizationMeta.vcr_MetaKey + Lang.int_LangId %>" value="Save" />
<div id="errors"></div>
<div id="answers"></div>
<% } %>
Controller:
[HttpPost]
[ValidateInput(false)]
public ActionResult EditOrganizationMeta(FormCollection collection)
{
return Json(new { Answer = "Record Successfully Saved", ErrorMessages = "Title is required" });
}
The thing is that success method in the javascript is not getting the required parameters. It is printing undefined there. Is there a problem in javascript method OnSuccess?