So I have this controller called Cars, and it has:
namespace MySite.Controllers
{
public class CarsController : ApplicationController
{
public ActionResult Index()
{
return View();
}
public ActionResult New()
{
return View();
}
[httppost]
public ActionResult New()
{
return View();
}
public ActionResult Details(int id)
{
return View();
}
}
}
Global asax
routes.MapRouteLowerCase(
"Cars", // Route name
"Cars/{id}", // URL with parameters
new { controller = "Cars", action = "Details", id = URLParameter.Optional}
);
routes.MapRouteLowerCase(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = URLParameter.Optional} // Parameter defaults
);
So following is the error I’m getting:
the parameters dictionary contains a null entry for parameter of non
nullable type for method in
NOTE: It’s getting me redirected to the “Details” View and is asking for an int even thought I wanted to go to the “New” view. I’m not really sure what’s happening? I basically wanted to have my urls lowercased while removing the “action” on the url on the Promoter routing…Does that make sense?
Anyhelp is appreciated! Thanks!!!
Your routing is invalid
Take a look at the first route definition:
And when you access
Cars/Newthis first route gets hit because all parameters are easily applied as:"Cars""Details""New"If you’d like the first route definition to only cover certain IDs you should put a constraint onto it or change your routing. Constraint for numeric IDs should look like this:
When you’d access
Cars/Newfirst route wouldn’t be hit becauseNewdoesn’t satisfy ID constraint so route processing would continue with the next route (which would resolve it just fine – as it should).Mind the fact, that
idisn’t optional anymore. In case of putting a constraint onto it it can’t be. If you have aDetailscontroller action it should most probably display some certain details. So it actually needs some ID.