您的位置:首页 > 编程语言 > ASP

Asp.Net MVC 利用ReflectedActionDescriptor判断Action返回类型

2015-11-03 11:07 363 查看
System.Web.Mvc.ReflectedActionDescriptor descriptor = filterContext.ActionDescriptor as

System.Web.Mvc.ReflectedActionDescriptor;
if (descriptor != null)
{
Type actionType =descriptor.MethodInfo.ReturnType;
if (actionType.Equals(typeof(ActionResult)))
{
if (actionType.IsSubclassOf(typeof(JsonResult)))
{
Response.Write("JsonResult");
}
else if (actionType.IsSubclassOf(typeof(ContentResult)))
{
Response.Write("ContentResult");
}
else
{
Response.Write("ViewResult");
}
}
else
{
if (actionType.Equals(typeof(JsonResult)))
{
Response.Write("JsonResult");
}
else if (actionType.Equals(typeof(ContentResult)))
{
Response.Write("ContentResult");
}
else
{
Response.Write("ViewResult");
}
}
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: