Pergunta

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.

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top