我无法重定向到区域,出现一条消息“处理请求时发生未处理的异常。InvalidOperationException:没有路由与提供的值匹配”。没有路由与提供的值匹配。
Startup.cs
我创建了以下路线:
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;
}
PacienteController.cs
我正在使用这些属性
[AllowAnonymous]
[Area("Paciente")]
[Route("Paciente")]
public class PacienteController : Controller
{
//[Authorize]
public ActionResult Index()
{
return View();
}
}
答案 0 :(得分:1)
需要指定区域,但是没有RedirectToAction的重载将其作为直接参数。因此,您需要这样做:
redirecionar = RedirectToAction("Index", "Paciente", new { area = "Paciente" });
侧面说明:建议不要将控制器和区域命名为相同的名称。考虑该区域的Paciente(Pacientas?)的复数。