MVC3 url 路由 - 使用先前的 url 渲染视图(如回发)

发布于 2024-12-22 21:55:02 字数 788 浏览 1 评论 0原文

我有一个控制器,它有一个 Create 方法来处理表单中的 HttpPost 数据。包含表单的页面通过 URL 访问

CallOutcome/Call?orderId=114565

当提交表单时,我执行 db insert & 操作。创建一个视图模型对象,该对象返回到视图以再次显示表单。这工作正常,但是 URL 现在已更改为我的操作方法的名称:

CallOutcome/Create

How can I make it show the raw URL?期望的结果是它像回发一样工作,即重新显示相同的页面和 URL。

这是我的(简化的)操作方法,它将 CallDetailsViewModel 对象返回到名为“Call”的视图:

[HttpPost]
 public ActionResult Create(GGAP_CallOutcome callOutcome)
{
    if (ModelState.IsValid)
    {
        callRepository.SaveCallOutcome(callOutcome);
        return View("Call", new CallDetailsViewModel{
            CustomerOrder = new CustomerOrder{},
            CallOutcome = new CallOutcome{},
            Task = new Task{}
         });
     }
 }

I have a Controller which has a Create method to handle HttpPost data from a form. The page containing the form is accessed by the URL

CallOutcome/Call?orderId=114565

When the form is submitted, I do a db insert & create a view model object which is returned to the view to display the form again. This works fine, however the URL has now changed to the name of my action method:

CallOutcome/Create

How can I make it show the original URL? The desired result would be like that it worked like a postback, i.e. reshowing the same page and URL.

This is my (simplified) action method, which returns a CallDetailsViewModel object to a view named 'Call':

[HttpPost]
 public ActionResult Create(GGAP_CallOutcome callOutcome)
{
    if (ModelState.IsValid)
    {
        callRepository.SaveCallOutcome(callOutcome);
        return View("Call", new CallDetailsViewModel{
            CustomerOrder = new CustomerOrder{},
            CallOutcome = new CallOutcome{},
            Task = new Task{}
         });
     }
 }

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

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

发布评论

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

评论(1

绝對不後悔。 2024-12-29 21:55:02

回复不多!也许离圣诞节太近了?

作为记录,我使用了 RedirectToRoute:

return RedirectToRoute(new
{
   controller = "CallOutcome",
   action = "Call",
   orderId = Convert.ToInt32(callOutcome.OrderId)
});

这正是我想要的。

not many responses! too close to christmas maybe?

For the record, I used RedirectToRoute:

return RedirectToRoute(new
{
   controller = "CallOutcome",
   action = "Call",
   orderId = Convert.ToInt32(callOutcome.OrderId)
});

Which does exactly what I wanted.

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