For some reason, one of my own AJAX calls gets the "No parameters without constructor" error. Here is the code:
CallAndReplace(JSON.stringify(model), url, $("#panel")); function CallAndReplace(data, url, replace) { $.ajax({ url: url, type: "post", contentType: "application/json; charset=utf-8", data: data, success: function (result) { replace.html(result); }, error: function (x, e) { if (x.status == 0) { alert('You are offline!!\n Please Check Your Network.'); } else if (x.status == 404) { alert('Requested URL not found.'); } else if (x.status == 500) { alert('Internal Server Error.'); } else if (e == 'parsererror') { alert('Error.\nParsing JSON Request failed.'); } else if (e == 'timeout') { alert('Request Time out.'); } else { alert('Unknow Error.\n' + x.responseText); } } }); }
'model' is the viewmodel in my MVC-3 view, which I converted to a Javascript object. 'url' is a url created using the @@ Url.Action method ("Action", "Controller"). And $ ("# panel") is the area of ββthe div, which is replaced by the partial view returned by the controller action.
When I try to debug a project, it never gets into the action of the controller. When I created a dummy controller action without parameters, it gets there in debug mode. But I am obviously sending data. I can see that the data is published in Firebug (although for some reason it is not structured), but apparently it is not sent, and I do not know why.
I use CallAndReplace 20 in my code for other purposes and have never asked me this problem. I totally donβt understand why.
Edit: Here is the viewmodel class that I submit to the view:
public class AwardsEdit { public List<AwardsViewModel> Awards { get; set; } public int TitleId { get; set; } public List<Tuple<int, string>> Participants { get; set; } public List<Award1> AllAwards { get; set; } public List<Tuple<int, string>> AllAwardCompanies { get; set; } }
And the controller action I'm trying to call:
public PartialViewResult SaveAwards(AwardsEdit award) { if (ModelState.IsValid) { bool updated = _translator.UpdateAward(award); if (updated) { return PartialView("Details", _translator.GetAwards(award.TitleId)); } //else error ModelState.AddModelError("", "Award data was not saved."); } //on error, load meta data var data = _translator.GetAwards(award.TitleId, true); award.Participants = data.Participants; award.AllAwards = data.AllAwards; award.AllAwardCompanies = data.AllAwardCompanies; return ViewAwards(award.TitleId); }
The controller itself does not have a constructor method without parameters, and I use dependency injection, but I have other AJAX calls that cause various actions in this controller, and they work fine. I do not know why this one does not work.