如何调试 RedirectToAction
我正在尝试调试一个问题,其中 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一如既往,我一发帖,就终于弄清楚了。以前劫持提交的方法留下了一些 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.