MVC部分视图控制器未在负载上运行

时间:2019-01-21 10:16:44

标签: c# asp.net-mvc model-view-controller

我正在尝试将MVC部分视图加载到模式弹出窗口中。弹出窗口包含一个下拉列表,我正在尝试在加载视图时加载的ActionResult上填充该下拉列表。问题在于控制器代码未运行。

我的代码如下-

查看:

<div id="modal_form_horizontal_addnote" class="modal fade">
<div class="modal-dialog modal-md">
    <div class="modal-content">
        <div class="modal-header bg-primary">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h5 class="modal-title">Add Note</h5>
        </div>

        @Html.Partial("AddNote", new IHD.Core.Models.CreateTicketNoteModel { TicketHeaderId = Model.Id })
    </div>
</div>

局部视图:

@model IHD.Core.Models.CreateTicketNoteModel


@using (Html.BeginForm("AddNote", "Ticket", FormMethod.Post))
{
@Html.HiddenFor(model => model.TicketHeaderId)
@Html.AntiForgeryToken()
<div class="row">
    <div class="col-md-12">
        <div class="tab-content">
            <div class="tab-pane active" id="highlighted-justified-tab1">

                <div class="form-group">
                    @Html.LabelFor(model => model.WorkType, htmlAttributes: new { @class = "control-label col-md-2" })
                    <div class="col-md-12">
                        @Html.DropDownListFor(model => model.WorkType, new SelectList(Model.WorkTypeOptions, "Key", "Value", Model.WorkType), new { @name = "select", @class = "form-control" })
                        @Html.ValidationMessageFor(model => model.WorkType, "", new { @class = "text-danger" })
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-offset-2 col-md-10">
                    <input type="submit" value="Create" class="btn btn-default" />
                </div>
            </div>
        </div>
    </div>
</div>
}

控制器:

public ActionResult AddNotePhase(int id = 0, int taskId = 0)
    {
        CreateTicketPhaseNoteModel note = new CreateTicketPhaseNoteModel();
        note.TicketHeaderId = id;

        // Populate the work type dropdown list
        note.WorkTypeOptions.Add("", "-- Select a Work Type --");
        note.WorkTypes = _workTypeService.GetAll().ToList();
        foreach (var c in note.WorkTypes)
        {
            note.WorkTypeOptions.Add(c.Id.ToString(), c.Description);
        }

        //note.PhaseTask = taskId;

        return PartialView(note);
    }

1 个答案:

答案 0 :(得分:0)

未命中您的控制器代码,因为您要将模型传递给局部视图且未调用操作。您需要使用@{Html.RenderAction();}来调用具有适当值的操作。