添加PartialView时,从Controller更新视图不​​起作用

时间:2015-11-04 13:49:57

标签: c# asp.net-mvc

我再次无法更新我的观点:

@model CCM.WebApp.MVC.ViewModels.Workflow.Edit.EditWorkflowViewModel

@Html.TextBoxFor(m => m.Test, new { id = "txtbTest", @class = "form-control" })

<button class="btn btn-success" id="btnOk"><i class="fa fa-floppy-o"></i> Ok</button>

<div id="collapsePanelBody" class="panel-collapse collapse in">
    <div class="panel-body" id="partialWorkflowStepList">
        @{ Html.RenderPartial("../WorkflowStep/_WorkflowStepList", Model.IndexWorkflowStepViewModel); }
    </div>
</div>

控制器操作:

[HttpPost]
public ActionResult Edit(EditWorkflowViewModel viewModel)
{
    ModelState.Clear();
    //... Code to persist the viewModel Data...

    viewModel.Test = "changed";

    if (Request.IsAjaxRequest())
        return PartialView("_Edit", viewModel);
    return View("_Edit", viewModel);
}

只有在视图代码中删除部分时,TextBox的更新才有效:

@{ Html.RenderPartial("../WorkflowStep/_WorkflowStepList", Model.IndexWorkflowStepViewModel); }

我不明白,为什么它没有更新,当我在我看来有这个部分时。

请解释这种行为以及我如何解决这个问题

编辑:

局部视图:

@model CCM.WebApp.MVC.ViewModels.WorkflowStep.Index.IndexWorkflowStepViewModel

@if (Model.SubmitModel != null && Model.SubmitModel.Items != null && Model.SubmitModel.Items.Any())
{
    @*@Html.ShowPagerCount(@Model.SubmitModel.Items.ItemStart, @Model.SubmitModel.Items.ItemEnd, @Model.SubmitModel.Items.TotalItemCount)*@
}
<div class="clearfix"></div>
<div style="margin-top: 5px; margin-bottom: 5px; border: 1px solid #ddd;">
    <table class="table table-hover table-nobottom table-striped">
        <thead>
            <tr>
                <th>
                    # <i class="fa fa-fw fa-sort-alpha-asc" data-toggle="tooltip" data-placement="top" title="Sortierung: Schrittnummer (1-9)"></i>
                </th>
                <th>
                </th>
                <th>
                    Beschreibung
                </th>
                @*<th>
                        Kategorie
                    </th>*@
                <th class="text-center">
                    Status
                </th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            @if (Model.SubmitModel != null && Model.SubmitModel.Items != null && Model.SubmitModel.Items.Any())
            {
                foreach (var item in Model.SubmitModel.Items)
                {
                    <tr>
                        <td>
                            @item.StepNo
                        </td>
                        <td style="width: 80px;white-space:normal;word-wrap: break-word;" align="center">
                            <img src="@Url.Content(item.StepTypeImageUrl)" alt="IMAGES" title="@item.DisplayText.ToString()" />
                        </td>
                        <td style="max-width: 400px;white-space:normal;word-wrap: break-word;padding: 2px;">
                            <div>@Html.Raw(HttpUtility.HtmlDecode(@item.Description))</div>
                        </td>
                        @*<td>
                                @item.Category
                            </td>*@
                        <td class="text-center">
                            @if (item.IsActive)
                            {
                                <i class="fa fa-check" style="color: green;"></i>
                            }
                            else
                            {
                                <i class="fa fa-ban" style="color: red;"></i>
                            }
                        </td>
                        <td>
                            <div class="float-left">
                                <a href="@Url.Action("Edit", "WorkflowStep", new { id = item.PrimaryKey })"><span class="glyphicon glyphicon-edit big" data-toggle="tooltip" title="Datensatz ändern"></span></a>
                            </div>
                            <div class="float-left">
                                &nbsp;
                                <a href="@Url.Action("Delete", "WorkflowStep", new { id = item.PrimaryKey, title = item.DisplayText, workflowId = Model.SubmitModel.WorkflowId })" onclick="return confirm('Datensatz löschen?')"><span class="glyphicon glyphicon-trash big" data-toggle="tooltip" title="Datensatz löschen"></span></a>
                            </div>
                            <div class="float-left" style="display:@(item.StepNo == Model.SubmitModel.Items.Count ? "none;" : "inline;")">
                                &nbsp;
                                <a href="javascript:changeWorkflowStepPosition(@Model.SubmitModel.WorkflowId, @item.PrimaryKey, true);"><span class="glyphicon glyphicon-arrow-down big" data-toggle="tooltip" title="Position nach unten verschieben"></span></a>
                            </div>
                            <div class="float-left" style="display:@(item.StepNo == 1 ? "none;" : "inline;")">
                                &nbsp;
                                <a href="javascript:changeWorkflowStepPosition(@Model.SubmitModel.WorkflowId, @item.PrimaryKey, false);"><span class="glyphicon glyphicon-arrow-up big" data-toggle="tooltip" title="Position nach oben verschieben"></span></a>
                            </div>
                        </td>
                    </tr>
                }
            }
            else
            {
                <tr><td colspan="4">Keine Daten vorhanden</td></tr>
            }
        </tbody>
    </table>
</div>

EditWorkflowViewModel:

public class EditWorkflowViewModel : CreateWorkflowViewModel
{
    public string Test { get; set; }

    public EditWorkflowViewModel()
    {
        SubmitModel = new EditWorkflowSubmitModel();
    }
}

public class CreateWorkflowViewModel : BaseViewModel
{
    #region Properties
    public CreateWorkflowSubmitModel SubmitModel { get; set; }

    [Display(Name = "Farbe")]
    public List<SelectListItem> AvailableColors { get; set; }

    public IndexWorkflowStepViewModel IndexWorkflowStepViewModel { get; set; }

    #endregion

    public CreateWorkflowViewModel()
    {
        SubmitModel = new CreateWorkflowSubmitModel();
    }
}

IndexWorkflowStepViewModel:

public class IndexWorkflowStepViewModel : BaseViewModel
{
    #region Properties
    public IndexWorkflowStepSubmitModel SubmitModel { get; set; }
    public string WorkflowName { get; set; }
    #endregion

    #region Constructor
    public IndexWorkflowStepViewModel()
    {
        SubmitModel = new IndexWorkflowStepSubmitModel();
    }
    #endregion
}

0 个答案:

没有答案