重定向到使用&QUOT控制器散列; RedirectToAction" [英] Redirect to a hash from the controller using "RedirectToAction"

查看:84
本文介绍了重定向到使用&QUOT控制器散列; RedirectToAction"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我想MVC中控制器返回一个锚

Hello I want to return an anchor from Mvc Controller

控制器名称= DefaultController;

Controller name= DefaultController;

public ActionResult MyAction(int id)
{
        return RedirectToAction("Index", "region")
}

这样当指向索引网址是

So that the url when directed to index is

http://localhost/Default/#region

这样

<a href=#region>the content should be focus here</a>

我不问,如果你能做到这一点是这样的:的我怎么能一个锚标记添加到我的网址是什么?

推荐答案

我发现这种方式:

public ActionResult MyAction(int id)
{
    return new RedirectResult(Url.Action("Index") + "#region");
}

您也可以使用这个方法冗长:

You can also use this verbose way:

var url = UrlHelper.GenerateUrl(
    null,
    "Index",
    "DefaultController",
    null,
    null,
    "region",
    null,
    null,
    Url.RequestContext,
    false
);
return Redirect(url);

<一个href=\"http://msdn.microsoft.com/en-us/library/ee703653.aspx\">http://msdn.microsoft.com/en-us/library/ee703653.aspx

这篇关于重定向到使用&QUOT控制器散列; RedirectToAction&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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