具有多个列表和“返回列表”的 asp.net mvc 控制器关联
如果控制器中有 5 个列表视图,并且在每个列表中您都可以进行编辑、详细信息或删除。 在编辑、详细信息和删除页面上,您有一个“返回列表”链接。 “记住”必须返回哪个列表操作的最佳方法是什么?
作为解决方案,我在 ViewModel 中放入了一些信息(例如 CurrentAction),并在视图中使用了它。但如果你想将其与不同的控制器而不是一个控制器一起使用...... (您可以使用 Currentcontroller、CurrentArea,但这不是一个“漂亮”的解决方案)
public class MyController : Controller
{
public ActionResult Index()
{
...
}
public ActionResult List2()
{
...
}
public ActionResult List3()
{
...
}
public ActionResult List4()
{
...
}
public ActionResult Create(...)
{
...
}
[HttpPost]
public ActionResult Create(...)
{
...
}
public ActionResult Edit(...)
{
...
}
[HttpPost]
public ActionResult Edit(...)
{
...
}
public ActionResult Delete(...)
{
...
}
[HttpPost]
public ActionResult Delete(...)
{
...
}
}
谢谢
Filip
If you have 5 list views in a controller and in each list you can go to edit, details or delete.
On the edit, details and delete page youo have a link 'return to list'.
What's the best method to 'remember' to which list action you must return?
As a solution I've put some info like CurrentAction in the ViewModel and used that in the View. But if you want to use this with different controllers instead of one...
(You can use a Currentcontroller, CurrentArea, but that's not a 'beautifull' solution)
public class MyController : Controller
{
public ActionResult Index()
{
...
}
public ActionResult List2()
{
...
}
public ActionResult List3()
{
...
}
public ActionResult List4()
{
...
}
public ActionResult Create(...)
{
...
}
[HttpPost]
public ActionResult Create(...)
{
...
}
public ActionResult Edit(...)
{
...
}
[HttpPost]
public ActionResult Edit(...)
{
...
}
public ActionResult Delete(...)
{
...
}
[HttpPost]
public ActionResult Delete(...)
{
...
}
}
thanks
Filip
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 Request.UrlReferrer 属性 来检查用户从哪里来删除或编辑屏幕。然后绑定 url 以返回列表命令。
You can use Request.UrlReferrer Property to examine from where did user come to delete ot edit screens.Then bind url to return to list command.
您可以在调用者操作中设置 TempData["ReturnUrl"],然后使用它来设置返回列表超链接的 url。
You can set TempData["ReturnUrl"] in your caller action and then use it to set the url of return to list hyperlink.