0

I have a function calling a controller method in MVC3.

$.getJSON('@Url.Action("LoadCitiesByProvince", "Property")', { id: 1}, function (msg) {
    alert("Data Saved: " + msg);
});

The final rendered Javascript:

$.getJSON('/MySite/Property/LoadCitiesByProvince', { id: 1 }, function (msg) {
alert("Data Saved: " + msg);
}); 

Firebug reports the following error:

s is undefined
[Break On This Error]   

callbackContext = s.context || s,

When I debug my controller method is never hit. I have triple checked the controller method even calling it manually via the url in my browser (in whitch case it works as expected). This is my controller method:

[AcceptVerbs(HttpVerbs.Get)]
public JsonResult LoadCitiesByProvince(string id)
{
    var modelList = this.GetCities(Convert.ToInt32(id));

    var modelData = modelList.Select(m => new SelectListItem()
    {
        Text = m.Description,
        Value = m.Id.ToString(),

    });

    return Json(modelData, JsonRequestBehavior.AllowGet);
}

At this point all I want to see is my controller method being hit and data coming back.

5
  • Please post the JS as returned to the browser. Commented Jan 30, 2012 at 23:11
  • I added the rendered JS as requested. Commented Jan 30, 2012 at 23:17
  • It looks fine to me. Are you sure that the problem is related to the getJSON call? Do you not get this error if you comment it out? Commented Jan 30, 2012 at 23:29
  • 1
    If you're seeing that error in Firebug, it's because you have an error somewhere else on your page. Your getJSON call is just fine. Commented Jan 30, 2012 at 23:30
  • @BrentAnderson Thanks, that helped me to look in the right place! Commented Jan 30, 2012 at 23:47

1 Answer 1

1

The problem was with the jquery vsdoc javascript file included with MVC3. It causes this error. Simply Changing the javascript include line:

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

to

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

Here is a link to a question about this issue:

Updating vsDoc to 1.5 breaks all javascript

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.