这是我想要调用的控制器,这个控制器位于一个解决方案中但位于另一个类库中
[HttpGet]
[Route("Business/GetCountries")]
public JsonResult GetCountries(string countryName)
{
List<countries_model> countrylist = null;
var myresult = "{'name':'John', 'age':31, 'city':'New York' }";
return Json(myresult,JsonRequestBehavior.AllowGet);
}
这是我调用控制器的jquery ajax代码
baseUrl = "/Business/GetCountries";
function getCountries()
{
alert();
var obj = {};
obj.countryName = '';
$.ajax({
type: 'GET',
url: baseUrl,
dataType: 'json',
async: false,
success: function (data) {
console.log(data);
},
error: function (err) {
console.log(err);
}
});
}
这是我的路线配置
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Business",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Business", action = "GetCountries", id = UrlParameter.Optional }