I’ll show you what I did to work, check on your project:
First add route in startup:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "MinhasAreas",
template: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
Assign controllers within their respective areas:
[Area("Paciente")]
public class PacienteController : Controller
{
// GET: /<controller>/
public IActionResult Index()
{
return View();
}
}
Perform the redirect normally:
public class LoginController : Controller
{
public IActionResult Index()
{
return View();
}
public IActionResult GravarCadastro(string perfil) {
return RedirectToAction("Index", perfil, new { area = perfil });
}
}
I added the project on github for consultation, just click login and choose the profile to be redirected:
Project link:
https://github.com/superrfm/aspnetcore_areas
Testing
RedirectToAction("Index", "Paciente", new { area = "Paciente" })
– George Wurthmann
Note that ASP.NET MVC is not the same thing as ASP.NET Core. Another thing: always post the code in formatted text, not in images. This helps in visualization, indexing the question and does not prevent those who have blocks to understand the question.
– Jéf Bueno
Prefer to post code in text instead of image. The reason is here.
– Ronaldo Araújo Alves
@Georgewurthmann did not work, no:C
– rock.ownar
You can add the area settings mapped to the startup routes?
– Rafael
I have tried, used this code: app.Usemvc(Routes => { Routes.Maproute( name: "areas", template: "{area:exists}/{controller=Patient}/action=Index}/{id? }" ); });
– rock.ownar