mvc如何自动自动加参数
1个回答
2014-11-14
展开全部
public class HomeController : Controller
{
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
var methodInfo = ((ReflectedActionDescriptor) filterContext.ActionDescriptor).MethodInfo;
foreach (var p in methodInfo.GetParameters())
{
if (p.ParameterType.IsValueType)
{
filterContext.ActionParameters[p.Name] = Activator.CreateInstance(p.ParameterType);
}
}
}
public ActionResult Index(int para1, string para2, int para3, bool para4)
{
Debug.Print("para1:{0} para2:{1} para3:{2} para4 :{3}",para1, para2, para3, para4);
return View();
}
}
{
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
var methodInfo = ((ReflectedActionDescriptor) filterContext.ActionDescriptor).MethodInfo;
foreach (var p in methodInfo.GetParameters())
{
if (p.ParameterType.IsValueType)
{
filterContext.ActionParameters[p.Name] = Activator.CreateInstance(p.ParameterType);
}
}
}
public ActionResult Index(int para1, string para2, int para3, bool para4)
{
Debug.Print("para1:{0} para2:{1} para3:{2} para4 :{3}",para1, para2, para3, para4);
return View();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询