返回JSON或部分html的ASP.NETMVC控制器操作我正在尝试创建控制器操作,它将根据参数返回JSON或部分html。将结果异步返回到MVC页面的最佳方法是什么?
3 回答
至尊宝的传说
TA贡献1789条经验 获得超10个赞
if (Request.AcceptTypes.Contains("text/html")) {
return View();}else if (Request.AcceptTypes.Contains("application/json")){
return Json( new { id=1, value="new" } );}else if (Request.AcceptTypes.Contains("application/xml") ||
Request.AcceptTypes.Contains("text/xml")){
//}$.get(url, null, function(data, textStatus) {
console.log('got %o with status %s', data, textStatus);
}, "json"); // or xml, html, script, json, jsonp or text添加回答
举报
0/150
提交
取消
