首页 > 解决方案 > 如何将下拉值传递给局部视图

问题描述

我正在尝试将下拉列表的选定值传递给部分视图。

这是被调用的 ActionResult

public ActionResult AddContact(int customerId = 0)
{
    ContactModel contact = new ContactModel();
    contact.CustomerId = customerId;

    return PartialView(contact);
}

这是包含所需值的下拉菜单

@Html.DropDownListFor(model => model.CustomerId, new SelectList(Model.CustomerOptions, "Key", "Value", Model.CustomerId), new { @id = "category", @name = "category", @class = "select-search" })

这是我们需要参数的模态弹出窗口

<div id="modal_form_horizontal_addcontact" class="modal fade">
    <div class="modal-dialog modal-md">
        <div class="modal-content">
            <div class="modal-header bg-success">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h5 class="modal-title">Add New Contact</h5>
            </div>

            <div class="form-horizontal">
                <div class="modal-body">
                    @{Html.RenderAction("AddContact", "Ticket", new { CustomerId = Model.CustomerId });}
                </div>
            </div>
        </div>
    </div>
</div>

基本上,模式弹出窗口会为下拉菜单中选择的客户创建一个新联系人。我需要客户的 ID 才能添加联系人。

标签: c#asp.net-mvc

解决方案


推荐阅读