ASP.Net MVC RedirectToAction锚 [英] ASP.Net MVC RedirectToAction with anchor

查看:133
本文介绍了ASP.Net MVC RedirectToAction锚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题:
例如,我有这样的路线:

  routes.Add(新干线(论坛/线程/ {} threadOid /最后一个新MvcRouteHandler())
           默认值=新RouteValueDictionary(
             新{控制器=线程,行动=ShowThreadLastPostPage})
        约束=新RouteValueDictionary(新{threadOid = @^ \\ D + $})
    }
);

有没有使用RedirectToAction方法浏览到这样的URL的方式:


  

论坛/线程/ {} threadOid /最后一个#postOid



解决方案

我觉得你应该用 Url.RouteUrl <一起使用重定向方法/ code>来完成它。

 返回重定向(Url.RouteUrl(新{控制器=线程,行动=ShowThreadLastPostPage,threadOid =的threadId})+#+ postOid);

I have the following problem: For example I have route like this:

routes.Add(new Route("forums/thread/{threadOid}/last", new MvcRouteHandler())
           Defaults = new RouteValueDictionary(
             new { controller = "Thread", action ="ShowThreadLastPostPage"}),
        Constraints = new RouteValueDictionary(new { threadOid = @"^\d+$" })
    }
);

Is there a way using RedirectToAction method navigate to the URL like this:

forums/thread/{threadOid}/last#postOid

解决方案

I think you should use the Redirect method along with Url.RouteUrl to accomplish it.

return Redirect(Url.RouteUrl(new { controller = "Thread", action = "ShowThreadLastPostPage", threadOid = threadId }) + "#" + postOid);

这篇关于ASP.Net MVC RedirectToAction锚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆