0
我有一個使用2種型號的形式,所以我包括這樣:ValidationMessage沒有顯示出來
@model Equipment.Models.PublicViewModel
其中PublicViewModel是
namespace Equipment.Models
{
public class PublicViewModel
{
public Device Devices { get; set; }
public UserCredentials Data { get; set; }
}
}
例如UserCredential類看起來像:
namespace Equipment.Models
{
public class UserCredentials
{
[Required]
public string UserName { get; set; }
[Required]
public string Password { get; set; }
}
}
和我的形式:
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<hr />
@Html.ValidationSummary(true)
<div class="input-group">
@Html.LabelFor(model => model.Data.UserName, new { @class = " input-group-addon" })
@Html.TextBoxFor(model => model.Data.UserName, new { @class = "form-control" })<br />
@Html.ValidationMessageFor(model => model.Data.UserName)
</div>
...
<div class="input-group">
@Html.LabelFor(model => model.Devices.DeviceSerialNumber, new { @class = " input-group-addon" })
@Html.TextBoxFor(model => model.Devices.DeviceSerialNumber, new { @class = "form-control" })<br />
@Html.ValidationMessageFor(model => model.Devices.DeviceSerialNumber)
</div>
...
}
在其他形式,當我只使用一個模型一切正常。 誰能告訴我爲什麼這不適用於2個型號?