在创建 MVC 自定义模型绑定器以将多个模型元组发布到控制器时需要帮助。从未使用过自定义模型绑定器。已经查看了这个问题的其他答案,但是在处理模型元组或提供所需的解决方案方面似乎没有接近。任何想法表示赞赏。- 谢谢
看法
@model Tuple<Contact, Communications, Addresses>
@using (Html.BeginForm()) {
<div id="contact">
<div class="editor-label">
@Html.LabelFor(m => m.Item1.FirstName)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.Item1.FirstName)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.Item1.LastName)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.Item1.LastName)
</div>
<div>
<input type="submit" value="Create" />
</div>
</div>
<div id="communication">
<div class="editor-label">
@Html.LabelFor(m => m.Item2.TelephoneValue)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.Item2.TelephoneValue)
</div>
</div>
<div id="address">
<div class="editor-label">
@Html.LabelFor(m => m.Item3.Address1)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.Item3.Address1
</div>
<div class="editor-label">
@Html.LabelFor(m => m.Item3.City)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.Item3.City)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.Item3.StateProvince)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.Item3.StateProvince)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.Item3.PostalCode)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.Item3.PostalCode, new { id = "zip", style = "width:90px;" })
</div>
</div>
}
控制器
[HttpPost]
public ActionResult CreateContact(Tuple<Contact, Communications, Addresses> tuple) {
//…. Do tuple processing to transfer values to add values to App Service here.
}