I have a project that has three different controllers for tax, Sales, Gas, Utility. When I invoke one from the menu like http://localhost/tax/salestax it nicely goes to the Index method. Route config is like this:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
This works fine when calling the method to make a new entry but fails when calling an entry already entered from a list with the transaction number.
public ActionResult Index(long? id)
{
if (id = null)
{
return newTaxRequest();
}
return existingTaxRequest(id.ToString());
}
The page will not even break on the Index when called with the parameter:
http://localhost/tax/salestax/500030
The Home controller Index action method is simply:
public ActionResult Index()
{
return View();
}
How do I configure the controller actions or the route map to fix this?
OK, the senior guy here changed the route to:
salestax/{id}
with the action of "Index", which does allow me to see a created trans. And he added two more route for the other two types. However, now I cannot create a new one since it always goes back to the Index, in an endless cycle. If I change it to:
salestax/{action}/{id}
I am able to create a new trans, but unable to see the created one with the error that http://localhost/tax/salestax/500030 cannot be found.
Any other ideas?
http://localhost/tax/salestax
would go to theIndex
action of thetax
controller. It would invokesalestax
action of thetax
controller. So, try going tohttp://localhost/tax/500030
- that should invokeIndex
action with the parameter. Home controller and it'sIndex
action is not relevant to your problem. – Floremin