I am trying to overload the MVC controllers, how can I overload it properly?
I want to list all companies in my website in a ListCompanies() controller like below
http://localhost:21047/Home/ListCompanies
and I want to add search criteria if user makes a search like below
http://localhost:21047/Home/ListCompanies/sera
"sera" is my search criteria. if search criteria exist, I want to filter my search result according to the search criteria.
here are my controllers
public ActionResult ListCompanies()
{
return View(db.AY_COMPANIES);
}
[ActionName("ListCompaniesFilter")]
public ActionResult ListCompanies(string filter)
{
var filtredCompanies = from c in db.AY_COMPANIES
where c.COMPANY_FULL_NAME.StartsWith(filter)
select c;
return View(filtredCompanies);
}
and here is my ROUTING which behaves not correctly.
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
"Home", // Route name
"{controller}/{action}/{filter}", // URL with parameters
new { controller = "Home", action = "ListCompanies", filter = UrlParameter.Optional} // Parameter defaults
);
}
My MapRoutes are not correct because it doesnt get the search criteria properly. how can I fix this?