문제

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