Reputation: 1941
I have a Search controller with a generic Search() action that takes several parameters and has a bunch of logic. I'd like to call this from other controllers without having a lot of copy/paste code.
I'd like to call this action from these different urls/controllers.actions.
/Search/Search?text=mySearchText
/User/SearchTransactions?type=purcahse
/Transactions/UserSearch?UserId=1
I could move the method to a baseController but I'd have to call /Search on each controller and I'd like to have them all named differently.
Upvotes: 0
Views: 1316
Reputation: 1579
you already have your solution man put it in base controller and decorate it with actionName attribute
like
[ActionName("Search1")]
public ActionResult SearchText(string text) {
return View();
}
[ActionName("Search2")]
public ActionResult SearchType(string Type) {
return View();
}
[ActionName("Search3")]
public ActionResult searchId(int ID) {
return View();
}
now you can do like
/search1
/search2
/search3
Upvotes: 1