Iulian
Iulian

Reputation: 1200

Can't pass a parameter to a asp.net mvc controller

I have a controller that looks like this:

public ActionResult Sold()
        {
            using (WipDBEntities db = new WipDBEntities())
            {
                ViewData.Model = db.GetSummaryProiect("Test").ToList();
                return View();
            }
        }

This is working fine except that when i try to get the parameter from the url my view is empty

public ActionResult Sold(string PrjCode)
        {
            using (WipDBEntities db = new WipDBEntities())
            {
                ViewData.Model = db.GetSummaryProiect(PrjCode).ToList();
                return View();
            }
        }

I'm new to mvc so probably i'm doing something wrong, can you help me ?

EDIT

I have a route to handle this

        routes.MapRoute(
                "Componente", // Route name
                "Componente/Sold/{PrjCode}", // URL with parameters
                new { controller = "Componente", action = "Sold", PrjCode= "" } // Parameter defaults
            );

The url looks like [hostname]/Componente/Sold/Test

Upvotes: 0

Views: 1927

Answers (1)

Brian Ball
Brian Ball

Reputation: 12596

Where are you expecting that value to come from? If you are using the default route of {controller}/{action}/{id}, and your value is in the {id} placeholder then the parameter name on your action method needs to be id.

Upvotes: 3

Related Questions