I am relatively new to MVC, done the basis from web tutorials. I am now in the process of starting an app from scratch, without bastardizing tutorials.

I am trying to map a route, like this

 routes.MapRoute(
                name: "DrillDown",
                url: "Home/CupboardDrillDown/{productcat}");

However evertime i enter

/home/CupboardDrillDown/1

in my browser i get an error saying that productcat is null, i think that its using the default route, so its passing ID instead of productcat.

The parameters dictionary contains a null entry for parameter 'productcat' of non-nullable type 'System.Int32' for method

Thanks in advance.

有帮助吗?

解决方案

if you are using productcat in your route then your action parameter must be also named as productcat.

please follow an example below

 routes.MapRoute(
            name: "DrillDown",
            url: "Home/CupboardDrillDown/{productcat}"
  );

public ActionResult CupboardDrillDown(int productcat)
    {
        return View();
    }

Hope that helps.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top