2
我正在嘗試將WarningCheck
屬性添加到我的模型中,我將覆蓋OnActionExecuting
來控制驗證。問題是代碼從未被調用過。MVC 3:ActionFilterAttribute和OnActionExecuting不會觸發
WarningCheckAttribute
[AttributeUsage(AttributeTargets.All)] // I have tried other targets too without success
public class WarningCheckAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
base.OnActionExecuting(filterContext);
/* DO SOME STUFF */
}
}
型號
public class Ticket
{
...
[StringLength(50)]
[Display(Name = "Cliente")]
[Required(ErrorMessage = "Il Cliente è obbligatorio.")]
[WarningCheck]
[MaxLength(50, ErrorMessage = "Il nome del Cliente può essere al massimo di 20 cifre."), MinLength(3, ErrorMessage = "Il nome del Cliente è troppo corto. Inserire almeno 3 caratteri.")]
public string Cliente { get; set; }
...
非常感謝!我是新手。 – Larry 2012-03-03 20:57:09
@Larry你應該至少看看一些視頻教程。驗證以比使用動作過濾器 – archil 2012-03-03 21:07:08
THX archil更好的方式完成。任何教程的建議,請問? – Larry 2012-03-04 08:13:46