gpt4 book ai didi

asp.net-mvc - asp mvc : specifying a view name does not change the url

转载 作者:行者123 更新时间:2023-12-04 12:15:00 24 4
gpt4 key购买 nike

我的HttpPost Controller 中有一个create Action 。在该操作内,我将记录插入db中,然后返回一个指定其他操作名的 View ,因为我想将用户带到其他地方,例如转到他们刚刚创建的记录的详细信息 View ,然后传入当前模型,因此我不必重新加载他们刚刚输入的数据。不幸的是,地址栏中的URL仍显示原始的create操作。

[HttpPost]
public ActionResult Create(MyModel model)
{
//Insert record
...
//Go to details view, pass the current model
//instead of re-loading from database
return View("Details", model);
}

如何获取显示“ http://myapp/MyController/Details/1”而不是“ http://myapp/MyController/Create/1”的网址?是否可以,或者我必须进行重定向?我希望我可以避免重定向...

最佳答案

我认为您想使用RedirectToAction()而不是View()。看一下以下问题:How to RedirectToAction in ASP.NET MVC without losing request data

关于asp.net-mvc - asp mvc : specifying a view name does not change the url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1993301/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com