[英]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 这工作正常,除了当我尝试从url获取参数时,我的视图为空
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 ? 我是MVC的新手,所以我可能做错了什么,您能帮我吗?
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
网址看起来像
[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
. 如果您使用的是
{controller}/{action}/{id}
的默认路由,并且您的值位于{id}
占位符中,那么action方法上的参数名称必须为id
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.