我有一个处理文件上传的控制器。最终我希望能够创建属性来装饰我的控制器动作,比如
[HttpPostedFileType("zip")]
目前,我创建了这个扩展方法,我在操作中使用它。
public static string GetFileExtension(this HttpPostedFileBase file)
{
if (!file.FileName.Contains('.'))
throw new FormatException("filename does not contain extension");
return file.FileName.Split(".".ToCharArray()).Last();
}
动作签名为
[HttpPost]
public ActionResult Shapefile(HttpPostedFileBase file)
{
file.GetFileExtension()
...
}
我的问题是,我能在action executing的属性中得到参数吗?或者,由于生命周期还没有到达action方法,它们还没有被绑定吗?我应该用HttpPostedFileBase属性创建一个模型并创建一个验证属性吗?建议?