我有一个helper类,它被传递了一个值数组,然后从我的Model中传递给一个新类。如何验证给这个类的所有值都是有效的?换句话说,如何在非控制器类中使用ModelState的功能。
从控制器执行以下操作:
public ActionResult PassData()
{
Customer customer = new Customer();
string[] data = Monkey.RetrieveData();
bool isvalid = ModelHelper.CreateCustomer(data, out customer);
}
从帮助器:
public bool CreateCustomer(string[] data)
{
Customter outCustomer = new Customer();
//put the data in the outCustomer var
//??? Check that it's valid
}
https://stackoverflow.com/questions/11150375
复制相似问题