我有一个控制器操作返回一个JSON数据。它可以通过getJSON方法轻松访问。但我希望通过Web API检索JSON数据。是否可以通过web API返回json数据?
我的控制器代码是
public ActionResult GetProfile(string profileName)
{
var profileDataService = new BokingEngine.MasterDataService.GetProfileDataService();
var request = new ProfileSearchCriteria { Name = profileName };
var profileDetails = profileDataService.GetList(request);
return Json(profileDetails, JsonRequestBehavior.AllowGet);
}
[检查此链接](http://stackoverflow.com/questions/9847564/how-do-i-get-asp-net-web-api-to-return-json-instead-of-xml-using -chrome)和[链接2](http://www.hanselman.com/blog/OneASPNETMakingJSONWebAPIsWithASPNETMVC4BetaAndASPNETWebAPI.aspx) – 2013-03-13 06:05:05
顺便说一句你的代码使用的是ASP.NET MVC,而不是ASP.NET Web API。您是否尝试将MVC的代码转换为Web API或其他东西? – Eilon 2013-03-13 06:14:11