我有一组来自应用程序的另一个无法修改的模型类。这些没有我需要的验证属性(例如RemoteAttribute)。我如何去添加这些?我无法将[MetadataTypeAttribute]添加到模型。ASP.NET MVC3 - 不可变模型 - 添加验证属性
举例说明:
//in Models.dll
//remember: I can't modify this
public class Product
{
string Name { get; set; }
}
//in Web.dll
public class ProductController
{
// GET: /Product/
public ActionResult Index()
{
return View(new Product());
}
}
//what i need:
public class ProductMetadata
{
[Remote("Foo", "Bar")]
[RegularExpression]
string Name { get; set; }
}
这是在任何可能的方式,而不产生排序的ViewModel类的东西?
Unmutable?我认为你的意思是[不可变](http://www.merriam-webster.com/dictionary/immutable)。 – 2011-05-24 13:44:31