需要幫助創建MVC自定義模型綁定器以將多個模型元組發佈到控制器。從未使用自定義模型聯編程序。已經看過這個問題的其他答案,但似乎並沒有接近處理模型的元組或提供所需的解決方案。任何想法都表示讚賞。 - 感謝爲模型元組創建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.
}