I'm building an intranet where I have the following home controller:
[Route("{action=index}")]
public class HomeController : Controller
{
public ActionResult Index()
{
return View(HomeModelBuilder.BuildHomeModel());
}
public ActionResult FormsHome()
{
return View(HomeModelBuilder.BuildFormsHomeModel());
}
}
I'm trying to get my forms homepage to have a url of http://intranet/forms
so I thought I could do this using the following routing attribute:
[Route("~/forms")] // have also tried 'forms' and '/forms'
public ActionResult FormsHome()
but when I go to the url, it complains that multiple controllers have that route:
The request has found the following matching controller types: HRWebForms.Website.Controllers.ChangeDetailsController HRWebForms.Website.Controllers.InternalTransferController HRWebForms.Website.Controllers.LeaverController ...
I have also tried adding [RoutePrefix("")]
to the controller but this didn't work either
Is there a way to give that action a url of "forms" (without any controller or without adding a separate forms controller with an index) by just using routing attributes?
Ok so ranquild's comment pushed me in the right direction. In my route config, I had the default route of
So that my homepage would still work on the url with nothing in. If I changed this to
It seemed to solve the problem