You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改MVC控制器Action,使Contact跳转至Index#contact-us

如何修改Contact Action适配页面锚点迁移需求?

原来的Contact Action是直接返回对应视图,现在需要将访问/contact的请求重定向到首页的#contact-us锚点位置,你可以这样修改代码:

public ActionResult Contact()
{
    // 生成首页URL并拼接锚点,完成重定向
    return Redirect(Url.Action("Index") + "#contact-us");
}

说明:

  • Url.Action("Index")会根据路由配置生成首页的正确URL(比如website.pt)
  • 手动拼接#contact-us锚点,客户端跳转后会自动定位到页面中对应id="contact-us"的元素位置
  • 使用Redirect方法会触发客户端跳转,浏览器地址栏会更新为website.pt#contact-us,符合你的迁移需求

内容的提问来源于stack exchange,提问作者Patrick

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 08:20:49