MVC3 url 路由 - 使用先前的 url 渲染视图(如回发)
我有一个控制器,它有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
回复不多!也许离圣诞节太近了?
作为记录,我使用了 RedirectToRoute:
这正是我想要的。
not many responses! too close to christmas maybe?
For the record, I used RedirectToRoute:
Which does exactly what I wanted.