.NET: Microsoft MVC Ajax Helper Return Object

8/16/2013 5:03:03 PM

When you use the Microsoft MVC View Helpers to create an ajax form, you can specify an "onComplete" javascript function to call with the response object. Use the following javascript to convert that response object into a json object to use the returned values.

//Ajax Helper Code
@using (Ajax.BeginForm("Action", "Controller", new AjaxOptions() { OnComplete = "onComplete_DoSomething" }))

//Javascript
function onComplete_DoSomething(result)
{
	var obj = jQuery.parseJSON(result.responseText);        
	if (obj.Success == true) //assuming success is part of the response
	{            
	
	}        
}