我有一个名为 Server 的模型类,我创建了一个新的 ServerToEdit viewModel 类,如下所示:-
public class ServerToEdit
{
public Server Server { get; set; }
[Required]
public String IPAddress { get; set; }
}
创建视图的一部分是:-
model TMS.ViewModels.ServerToEdit
@* This partial view defines form fields that will appear when creating and editing entities *@
@Html.AntiForgeryToken()
<div class="editor-label">
@Html.LabelFor(model => model.Server.CustomerName)
</div>
<div class="editor-field">
@Html.EditorFor(model =>model.Server.CustomerName)
@Html.ValidationMessageFor(model =>model.Server.CustomerName)
</div>
<div class="editor-label">
IP Address
</div>
<div class="editor-field">
@Html.EditorFor(model => model.IPAddress)
@Html.ValidationMessageFor(model => model.IPAddress)
</div>
IPAddress
<div class="editor-label">
@Html.LabelFor(model =>model.Server.ILOIP)
</div>
<div class="editor-field">
@Html.EditorFor(model =>model.Server.ILOIP)
@Html.ValidationMessageFor(model =>model.Server.ILOIP)
</div>
创建肌动蛋白方法是:-
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(Server server, TechnologyIP technologyIP)
{
try
{
if (ModelState.IsValid)
{
repository.InsertOrUpdateServer(server,technologyIP);
repository.Save();
return RedirectToAction("Index");
}
但是模型绑定器无法将我视图中的 IPAddress 字段绑定到 TechnologyIP.IPAddress 属性?技术IP模型类是:-
public class TechnologyIP
{
public String IPAddress { get; set; }
public int ID { get; set; }
}