gpt4 book ai didi

asp.net-mvc - 为模型元组创建 MVC 自定义模型绑定(bind)器

转载 作者:行者123 更新时间:2023-12-02 03:48:09 25 4
gpt4 key购买 nike

需要帮助创建 MVC 自定义模型绑定(bind)器以将多个模型元组发布到 Controller 。从未使用过自定义模型 Binder 。已经看过这个问题的其他答案,但是,在处理模型元组或提供所需的解决方案时似乎并没有接近。任何想法表示赞赏。 - 谢谢

查看

@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>
}

Controller

[HttpPost]
public ActionResult CreateContact(Tuple<Contact, Communications, Addresses> tuple) {
//…. Do tuple processing to transfer values to add values to App Service here.
}

最佳答案

为什么不尝试将“联系人、通信、地址”模型保留在新模型中并将其绑定(bind)到 View 。

这将使处理变得非常简单。

关于asp.net-mvc - 为模型元组创建 MVC 自定义模型绑定(bind)器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15576550/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com