【发布时间】:2011-04-21 18:42:33
【问题描述】:
我的问题类似于:
Compound View Model object causing remote validation failure
我的模型:
public class Address
{
public string Street { get; set; }
public string City { get; set; }
[Remote("CheckZip", "Validation")]
public string PostalCode { get; set; }
public string Country { get; set; }
}
public class OrderViewModel
{
public Address ShippingAddress { get; set; }
public Address BillingAddress { get; set; }
public string OrderItem { get; set; }
public string OrderQuantity { get; set; }
}
呈现的 HTML 创建字段 ShippingAddress_Postalcode 和 BillingAddess_PostalCode。
CheckZip 操作:
public ActionResult CheckZip (string PostalCode)
{
...
}
这当然不起作用,因为没有发送 PostalCode,而是发送了 ShippingAddress_Postalcode 或 BillingAddess_PostalCode。如何使用相同的 CheckZip 操作来处理多个属性中存在的相同子属性?
【问题讨论】:
标签: c# asp.net-mvc asp.net-mvc-3 validation