Redirect to a hash from the controller using “RedirectToAction”

前端 未结 4 1302
不知归路
不知归路 2020-11-29 22:41

Hello I want to return an anchor from Mvc Controller

Controller name= DefaultController;

public ActionResult MyAction(int id)
{
        return Redi         


        
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-29 23:14

    Great answer gdoron. Here's another way that I use (just to add to the available solutions here).

    return Redirect(String.Format("{0}#{1}", Url.RouteUrl(new { controller = "MyController", action = "Index" }), "anchor_hash");
    

    Obviously, with gdoron's answer this could be made a cleaner with the following in this simple case;

    return new RedirectResult(Url.Action("Index") + "#anchor_hash");
    

提交回复
热议问题