如何调试 RedirectToAction

发布于 2024-09-09 12:31:25 字数 2119 浏览 8 评论 0原文

我正在尝试调试一个问题,其中 RedirectToAction 似乎工作正常(即执行重定向到的操作),但指定的视图从未在客户端呈现,并且 url 未重写。我的问题实际上是我可以在哪里寻找调试这个?代码如下:

Form:

<%using (Html.BeginForm("Save", "Items", FormMethod.Post, new {id="ItemForm"})) {%>
  <%=Html.AntiForgeryToken()%>
   ..form contents elided...
       <%= Html.Button("btnSave", ViewData.Model.SaveMethod, HtmlButtonType.Submit) %>
       <%= Html.Button("btnCancel", "Cancel", HtmlButtonType.Button, 
                                "window.location.href = '" +      Html.BuildUrlFromExpressionForAreas<ItemsController>(c => c.Index()) + "';") %>     
<% } %>

Controller:

    [ValidateAntiForgeryToken]
    [Transaction]
    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Save(Item item)
    {
        if (item.Id == Guid.Empty)
            return Create(item);

        return Edit(item);
    }

    [ValidateAntiForgeryToken]
    [Transaction]
    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Edit(Item item)
    {
        if (ViewData.ModelState.IsValid)
        {
            ActionConfirmation updateConfirmation =
                _itemManagementService.UpdateWith(item, item.Id);

            if (updateConfirmation.WasSuccessful)
            {
                TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] =
                    updateConfirmation.Message;
                return RedirectToAction("Index");
            }
        }

        ItemFormViewModel viewModel =
            _itemManagementService.CreateFormViewModelFor(item, _indicatorManagementService, _strategyManagementService);
        return View(viewModel);
    }

    [Transaction]
    public ActionResult Index()
    {
        ItemsFormViewModel viewModel = _itemManagementService.CreateListFormViewModel(_indicatorManagementService,
                                                                                      _strategyManagementService);
        return View(viewModel);
    }

我正在使用自定义模型绑定器,但 model.IsValid 返回 true 并且对模型的更改成功保存。我不知道到哪里去追踪这个问题。

感谢您的关注。

I am trying to debug a problem wherein RedirectToAction appears to be working properly (i.e., the redirected-to Action is executed) but the specified View is never rendered on the client side and the url is not rewritten. My question is really where can I be looking to debug this? Here's the code:

Form:

<%using (Html.BeginForm("Save", "Items", FormMethod.Post, new {id="ItemForm"})) {%>
  <%=Html.AntiForgeryToken()%>
   ..form contents elided...
       <%= Html.Button("btnSave", ViewData.Model.SaveMethod, HtmlButtonType.Submit) %>
       <%= Html.Button("btnCancel", "Cancel", HtmlButtonType.Button, 
                                "window.location.href = '" +      Html.BuildUrlFromExpressionForAreas<ItemsController>(c => c.Index()) + "';") %>     
<% } %>

Controller:

    [ValidateAntiForgeryToken]
    [Transaction]
    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Save(Item item)
    {
        if (item.Id == Guid.Empty)
            return Create(item);

        return Edit(item);
    }

    [ValidateAntiForgeryToken]
    [Transaction]
    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Edit(Item item)
    {
        if (ViewData.ModelState.IsValid)
        {
            ActionConfirmation updateConfirmation =
                _itemManagementService.UpdateWith(item, item.Id);

            if (updateConfirmation.WasSuccessful)
            {
                TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] =
                    updateConfirmation.Message;
                return RedirectToAction("Index");
            }
        }

        ItemFormViewModel viewModel =
            _itemManagementService.CreateFormViewModelFor(item, _indicatorManagementService, _strategyManagementService);
        return View(viewModel);
    }

    [Transaction]
    public ActionResult Index()
    {
        ItemsFormViewModel viewModel = _itemManagementService.CreateListFormViewModel(_indicatorManagementService,
                                                                                      _strategyManagementService);
        return View(viewModel);
    }

I am using a custom model binder, but model.IsValid returns true and the changes to the model save successfully. I am at a loss as to where to look to track this down.

Thanks for looking.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

对岸观火 2024-09-16 12:31:27

一如既往,我一发帖,就终于弄清楚了。以前劫持提交的方法留下了一些 jquery。

As always, as soon as I post, I finally figure it out. Had some left over jquery from a previous approach that was hijacking the submit.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文