【发布时间】:2016-02-17 15:38:53
【问题描述】:
我需要在控制器操作中获取参数并验证此参数。例如:
public TestController
{
public ActionResult TestMethod(int testParamFromUri)
{
//here is my validation
if(testParamFromUri < 0)
{
throw new TestException();
}
if(testParamFromUri > 50)
{
testParamFromUri = 50;
}
//other code
}
}
我的问题:
是否可以像上面的方法一样创建可以进行验证的属性?
然后使用这个属性:
public ActionResult TestMethod([TestVerification]int testParamFromUri)
【问题讨论】:
标签: c# .net asp.net-mvc .net-4.5