Search code examples
asp.net-mvcdebuggingredirecttoaction

How to debug RedirectToAction


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.


Solution

  • 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.