C# 重定向到某个区域
我无法重定向到某个区域,出现一条消息“处理请求时发生未处理的异常。InvalidOperationException:没有与提供的值匹配的路由”。没有与提供的值匹配的路由 Startup.csC# 重定向到某个区域,c#,asp.net-core,asp.net-core-mvc,C#,Asp.net Core,Asp.net Core Mvc,我无法重定向到某个区域,出现一条消息“处理请求时发生未处理的异常。InvalidOperationException:没有与提供的值匹配的路由”。没有与提供的值匹配的路由 Startup.cs public async Task<IActionResult> GravarCadastro(CadastroModel novoUsuario) { RedirectToActionResult redirecionar; switch (novoUsuario.perfi
public async Task<IActionResult> GravarCadastro(CadastroModel novoUsuario)
{
RedirectToActionResult redirecionar;
switch (novoUsuario.perfil)
{
case 1:
//not Working
redirecionar = RedirectToAction("Index", "Paciente");
break;
case 2:
//not Working
redirecionar = RedirectToAction("Index", "medico");
break;
case 3:
//not Working
redirecionar = RedirectToAction("Index", "farmacia");
break;
case 4:
//not Working
redirecionar = RedirectToAction("Index", "laboratorio");
break;
default:
//not Working
redirecionar = RedirectToAction("Index", "paciente");
break;
}
return redirecionar;
}
我创建了以下路线:
routes.MapRoute("areaRoute","area:exists}/{controller=Admin}/{action=Index}/{id?}");
LoginController.cs
public async Task<IActionResult> GravarCadastro(CadastroModel novoUsuario)
{
RedirectToActionResult redirecionar;
switch (novoUsuario.perfil)
{
case 1:
//not Working
redirecionar = RedirectToAction("Index", "Paciente");
break;
case 2:
//not Working
redirecionar = RedirectToAction("Index", "medico");
break;
case 3:
//not Working
redirecionar = RedirectToAction("Index", "farmacia");
break;
case 4:
//not Working
redirecionar = RedirectToAction("Index", "laboratorio");
break;
default:
//not Working
redirecionar = RedirectToAction("Index", "paciente");
break;
}
return redirecionar;
}
需要指定该区域,但不存在将其作为直接参数的RedirectToAction重载。所以你需要做:
redirecionar = RedirectToAction("Index", "Paciente", new { area = "Paciente" });
旁注:不建议将控制器和区域命名为相同的名称。考虑这个地区的多元结构(PACIETAS)。 我试过这个,这个项目是葡萄牙语的,所以是“Paciente”。。。要有创意。我尝试在控制器中没有属性,但它不起作用