Asp.net 什么在MVC应用程序中处理ajax/json?

Asp.net 什么在MVC应用程序中处理ajax/json?,asp.net,ajax,asp.net-mvc,Asp.net,Ajax,Asp.net Mvc,我曾经使用asmx处理来自页面的ajax调用,但我读到它是一个遗留产品,与MVC应用程序不太兼容。现在,还有什么东西可以替代同样与MVC兼容的asmx?在控制器中使用动作方法,为您提供Ajax响应。您可以返回任何形式的数据,如HTML标记(使用视图、Json、string.Image等) 使用request.IsAjax方法,可以使用相同的操作结果为ajax请求和普通请求返回HTML标记 public ActionResul Getcustomer(int id) { var custome

我曾经使用asmx处理来自页面的ajax调用,但我读到它是一个遗留产品,与MVC应用程序不太兼容。现在,还有什么东西可以替代同样与MVC兼容的asmx?

在控制器中使用动作方法,为您提供Ajax响应。您可以返回任何形式的数据,如HTML标记(使用视图、Json、string.Image等)

使用request.IsAjax方法,可以使用相同的操作结果为ajax请求和普通请求返回HTML标记

public ActionResul Getcustomer(int id)
{
  var customer=dbcontext.Customer.Find(id);
  if(Request.IsAjax())
  {
     return View("PartialCustomerForm",customer);
  }
  return View("RegularCustomerForm",customer);

}
要从页面中调用这些方法,可以使用jQueryAjax

$.get("@Url.Action("GetItems","Customer")", { id: 3 },function(data){
   //do whatever with the response. //alert(data);
});

如何从javascript端调用这些成员?我会像在asmx中那样调用它们吗?@YonkShi:补充到我的答案中。
$.get("@Url.Action("GetItems","Customer")", { id: 3 },function(data){
   //do whatever with the response. //alert(data);
});