I have two controller, C1 and C2.
C2 has a method named M2 which is returning a JsonResult.
Now i am calling method M2 from view V1 using $.ajax call but I guess that the relative path to C2/M2 is not working fine.
$.ajax({
type: "GET",
url: "/C2/M2",
success: function (data) {
alert(data);
}
});
Notice:
View V1 is rendered using controller C1
What is wrong with this call ?
public class C1 : Controller
{
public ActionResult Package(object Id)
{
return View("PackageO");
}
}
public class C2: Controller
{
public JsonResult SelectAll()
{
return Json(_rep.SelectAll(), JsonRequestBehavior.AllowGet);
}
}
Under ready() of jQuery in View 'PackageO' i am using IIFE
$(function () {
var resultant = "";
$.ajax({
type: "GET",
url: "./C2/SelectAll",
//url: "@Url.Action('SelectAll', 'C2')",
done: function (data) {
alert("success");
},
fail: function (ex) {
alert("fail");
}
});
});