开发者

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

开发者 https://www.devze.com 2023-02-14 16:41 出处:网络
I have a controller that looks like this: public ActionResult Sold() { using (WipDBEntities db = new WipDBEntities())

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 fr开发者_StackOverflow社区om 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号