Take the 2-minute tour ×


var myObject = content.get_response().get_object();

However it just throws a "Microsoft JScript runtime error: Object doesn't support this property or method" when trying to invoke the Ajax POST.

My code:


public ActionResult Index(string message)


<!DOCTYPE html>

    <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>

    <script type="text/javascript">
        function JsonAdd_OnComplete(mycontext) {
            var myObject = mycontext.get_response().get_object();

        @using(Ajax.BeginForm("Index", "Home", new AjaxOptions() { HttpMethod = "POST", OnComplete = "JsonAdd_OnComplete" }))




Thanks in advance.

share|improve this question
I don't know ASP but are you sure that OnComplete = "JsonAdd_OnComplete" shouldn't maybe be OnComplete = JsonAdd_OnComplete ?? In other words, don't quote the function name ... –  Pointy Dec 27 '10 at 15:58
Yes, according to the documentation it should be "FunctionName". - I've tried OnComplete = JsonAdd_OnComplete too, however it just returns a compile error because its not a string. –  ebb Dec 27 '10 at 16:01
add comment

3 Answers

up vote 3 down vote accepted

AFAIK in ASP.NET MVC 3 RC MS AJAX has been deprecated in favor of jQuery which is used by all Ajax.* helper methods. Javascript has become unobtrusive as well. This means that you no longer have to call .get_response().get_object() but simply:

function JsonAdd_OnComplete(myObject) {
    // here myObject is already the JSON object 
    // as returned by the controller action
share|improve this answer
Actually, I gave that a shot when I wrote the code in my answer and it doesn't seem to work that way in the OnComplete method...assuming you use the old MicrosoftAjax methods :) –  BuildStarted Dec 27 '10 at 18:56
add comment

Have you looked at the OnSuccess method? When that method is called the object passed to it is a JSON object based on a JSONResult so you could do this...

<script type="text/javascript">
    function JsonAdd_OnSuccess(mycontext) {

    new AjaxOptions() { 
        HttpMethod = "POST", 
        OnSuccess = "JsonAdd_OnSuccess" })) {




In addition the OnComplete method returns an object that contains the following properties


You'll have to eval() the responseText to convert the text to JSON though.

share|improve this answer
I was soo hoping that your answer would work, but I get the following error when I do the eval(): Uncaught SyntaxError: Unexpected token : –  Serj Sagan Mar 22 '13 at 22:04
@SerjSagan sounds like your json might be invalid. –  BuildStarted Mar 22 '13 at 22:42
The Json is being returned by the MVC Controller JsonResult with return Json(new { result = true, inputs = mylist.ToList() }); See my answer to see how I got it to work... –  Serj Sagan Mar 22 '13 at 22:49
add comment

if you are using the method provided by BuildStarted, here's how to structure the eval:

var json = eval("(" + context.responseText + ")");
share|improve this answer
add comment

Your Answer


