0

I have this ajax call. This is the first time I'm experiencing this problem. First, the break point on my action is not being hit. Second, the success function is being executed. Third, the value of my storeList/data is the whole code of the whole body content. This might be caused of my action not being found.

$.ajax({
  type: 'POST',
  url: '/reports/GetStoreFranchiseList?franchiseId=' + franchiseId,
  success: function (storeList) {
    console.log(storeList);
    var appendStr = "<li><a href='#' onclick=changeStore('All', 'All')>All</a></li>";
    // $.each(storeList, function (k, v) {
    //   console.log(v);
    //   appendStr += "<li><a href='#' onclick=changeStore('" + v.Id + "','" + v.StoreName + "')>" + v.StoreName + "</a></li>";
    // });
    console.log(appendStr);
    $(".rptStoreDdl").html(appendStr);
    $("#rptStoreDdlDv").removeClass().addClass("btn-group");
  }
});

When I try uncommenting the each function, I get this error: Uncaught TypeError: Cannot use 'in' operator to search for '21748' in #<error>

Obviously because the data is wrong. Any Ideas guys? Thanks!

EDIT:

Tried accessing it via fiddler and I'm getting this: /Error/NotFound?aspxerrorpath=/reports/GetStoreFranchiseList

This triggers my customer error for not found. I'm really not sure why my action is not found.

Controller action:

[InPrivate]
public class ReportsController : Controller
{
    [HttpGet]
    public JsonResult GetStoreFranchiseList(string franchiseId)
    {
        var data = new List<Store>();

        if(WebUser.Franchisees != null && WebUser.Franchisees.Count() > 0)
        {
            data = WebUser.Franchisees.FirstOrDefault(a => a.Id == franchiseId).Stores;
        }

        return Json(data, JsonRequestBehavior.AllowGet);
    }
}
Luke Villanueva
  • 2,030
  • 8
  • 44
  • 94

2 Answers2

1

More than likely a silent exception is being raised. I also encountered this exact same problem. It is worth noting that, not all exceptions will trigger a run-time error, from the browser/client it may appear that a valid return type has been returned. In my case, I was able to use the Intellitrace feature of Visual Studio to sniff out the following silent exception:

"The JSON request was too large to be deserialized"

That gave me the clues I needed to fix the issue via this other Stack Overflow response

I suggest trying to use the Ultimate version of Visual Studio which comes with Intellitrace to see if some similar exception is interfering with your server side code and ultimately tricking the client into thinking a valid response was returned.

Best of luck

Community
  • 1
  • 1
glthomas
  • 105
  • 1
  • 7
0

Try specifying the url like this:

url: '../Reports/GetStoreFranchiseList?franchiseId=' + franchiseId,

OR

url: '@Url.Action("GetStoreFranchiseList","Reports")' + '?franchiseId=' + franchiseId,
Vivek Parekh
  • 1,075
  • 9
  • 25