ASP.NET MVC AJAX value not displaying

Posted by mazhar kaunain baig on Stack Overflow See other posts from Stack Overflow or by mazhar kaunain baig
Published on 2010-06-01T08:17:25Z Indexed on 2010/06/01 10:43 UTC
Read the original article Hit count: 309

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about JavaScript