开发者

asp.net mvc controller with multiple lists and "return to list" link

开发者 https://www.devze.com 2023-03-07 03:07 出处:网络
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\'.

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()
        {
        ...
    }开发者_如何学Go

    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


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.


You can set TempData["ReturnUrl"] in your caller action and then use it to set the url of return to list hyperlink.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号