简体   繁体   English

C# MVC RedirectToAction 未更新视图

[英]C# MVC RedirectToAction not updating View

I have a C# MVC website which has a controller that has multiple ActionResult methods inside of it.我有一个 C# MVC 网站,其中有一个 controller,其中有多个 ActionResult 方法。 I have the basic Index which just loads the initial page which has a form on it.我有一个基本索引,它只加载上面有一个表单的初始页面。 The user fills out this form and clicks submit.用户填写此表单并单击提交。 From there the form is serialized and send to the method directly below which does some stuff then redirects to another action.从那里,表单被序列化并发送到直接下面的方法,该方法执行一些操作,然后重定向到另一个操作。

    [HttpPost]
    public ActionResult GenerateDegreeAudit(FormCollection formCollection)
    {
        //Do Stuff

        //Then
        return RedirectToAction("Review");
    }

The Review method, shown below, is getting hit by my breakpoint.如下所示的 Review 方法被我的断点击中。

    public ActionResult Review()
    {
        ViewBag.Courses = DegreeAuditRequest.Courses;
        return View();
    }

As is the corresponding Review.cshtml file shown below.如下所示的相应 Review.cshtml 文件也是如此。

<div class="container">
<div class="row">
    <div class="box box-primary">
        @using (Html.BeginForm("Review", "DegreeAuditProcess", null, FormMethod.Post, new { @class = "form-horizontal", @role = "form", @id = "frmReview" }))
        {
        <div class="box-body">
            <table>
                <thead>
                    <tr>
                        <th></th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var course in ViewBag.Courses)
                    {
                    <tr>
                        <td><input type="text" class="form-control" value="@course.EventName" /></td>
                        <td><input type="text" class="form-control" value="@course.ScheduledTerm" /></td>
                    </tr>
                    }
                </tbody>
            </table>
        </div>
            <div class="box-footer">
                <div class="row">
                    <div style="width: 100%;">
                        <input type="button" class="btn btn-primary" value="Generate" id="btnDAPRocess" style="float: right; margin-right: 10px;" />
                    </div>
                </div>
            </div>
        }
    </div>
</div>

However the page doesn't update to show the HTML on the Review.cshtml file.但是,该页面不会更新以在 Review.cshtml 文件中显示 HTML。 What am I missing?我错过了什么?

The answer to this is incredibly obnoxious.这个问题的答案令人难以置信。 It has to do with how the initial form was submitted.它与初始表单的提交方式有关。 In order to hit GenerateDegreeAudit I was not using form.submit but rather using an Ajax call.为了达到 GenerateDegreeAudit 我没有使用 form.submit 而是使用 Ajax 调用。 Because of this MVC handles Ajax completely different from how it handles form.submit.因为这个 MVC 处理 Ajax 与它处理 form.submit 的方式完全不同。 Using form.submit works just fine.使用 form.submit 工作得很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM