我在mvc 4中有一个编辑视图。除了我想要改变城市的时候,一切似乎都很好。
<p>
<label for="Password">Password</label>
@Html.EditorFor(model => model.Password)
@Html.ValidationMessageFor(model => model.Password)
</p>
<p>
<label for="Address.City">City</label>
@Html.EditorFor(model => model.Address.City)
@Html.ValidationMessageFor(model => model.Address.City)
</p>
在用户类中,我有这样的解决方法
public virtual Guid? AddressId { get; set; }
public virtual Address Address { get; set; }
和地址类
public class Address : SequoiaPersistanceItemBase
{
[MaxLength(100)]
public virtual string Street { get; set; }
[MaxLength(100)]
public virtual string Street2 { get; set; }
[MaxLength(100)]
public virtual string City { get; set; }
[AuditDetail(Type = typeof(StateType))]
public virtual int? StateTypeId { get; set; }
public virtual StateType StateType { get; set; }
[MaxLength(100)]
public virtual string PostalCode { get; set; }
[AuditDetail(Type = typeof(CountryType))]
public virtual int? CountryTypeId { get; set; }
public virtual CountryType CountryType { get; set; }
[AuditDetail(Type = typeof(CountyType))]
public virtual int? CountyTypeId { get; set; }
public virtual CountyType CountyType { get; set; }
我现在的问题是,当我尝试编辑时,除了城市之外,所有内容都会更改(名字,姓氏,用户名,密码)。单击“保存”时,没有任何更改。但是,当我尝试创建新用户时,我可以添加地址,并在索引页面中显示。