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

如何从RedeAtendimentoController正确重定向到Rede_AtendimentoController?

解决方案

当你的控制器带有[RoutePrefix("Rede_Atendimento")]特性时,普通的RedirectToAction可能因为属性路由的匹配规则失效,你可以尝试以下几种方法解决:

方法1:直接重定向到路由前缀URL

因为Index是默认的Action方法,直接重定向到路由前缀对应的路径即可:

return Redirect("/Rede_Atendimento");

方法2:指定完整的路由参数

确保项目已启用属性路由(在RouteConfig中配置了routes.MapMvcAttributeRoutes()),然后传入正确的控制器和Action名称:

return RedirectToAction("Index", "Rede_Atendimento");

注意:控制器名称需去掉后缀Controller,这里填写Rede_Atendimento是正确的。

方法3:使用命名路由

给Index方法添加命名路由特性,通过路由名称精准跳转:

[RoutePrefix("Rede_Atendimento")]
public class Rede_AtendimentoController : Controller
{
    [Route("", Name = "RedeAtendimentoIndex")] // 空路径对应Index,设置路由名称
    public ActionResult Index()
    {
        // 方法逻辑
    }
}

重定向时调用:

return RedirectToRoute("RedeAtendimentoIndex");

排查要点

  • 确认Rede_AtendimentoController的Index方法是public访问权限,且返回ActionResult类型。
  • 检查项目路由配置中是否启用了属性路由,这是RoutePrefix特性生效的前提。
  • 排查是否存在其他路由规则与Rede_Atendimento前缀冲突,导致重定向路径被错误匹配。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 16:32:36