我正在开发 MVC 2 应用程序,但遇到了问题。我的代码如下所示:
public ActionResult Users()
{
try
{
var model = new List<User>
{
new User
{
Name = "Test",
UserID = 1,
Salary = 1000m
}
};
return View(model);
}
catch (Exception ex)
{
//Log exception
return View("ErrorPage");
}
}
[HttpPost]
public ActionResult Users(IEnumerable<User> users)
{
try
{
if (ModelState.IsValid)
{
return RedirectToAction("Index");
}
return View(users);
}
catch (Exception ex)
{
//Log exception
return View("ErrorPage");
}
}
和类用户
public class User
{
[Required]
public string Name{ get; set; }
[Required]
public int UserID{ get; set; }
[Required]
public decimal Salary{ get; set; }
}
我想创建自定义属性(DataAnnototation)来验证 IEnumerable 用户在发布表单时的工资总和是否小于 10000?我可以在这里做吗,因为我的模型是列表?