Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么路由值没有传递给MVC控制器?_C#_Asp.net Mvc - Fatal编程技术网

C# 为什么路由值没有传递给MVC控制器?

C# 为什么路由值没有传递给MVC控制器?,c#,asp.net-mvc,C#,Asp.net Mvc,在这里,我在我的ViewModel中迭代产品: @foreach (var p in Model.Products) { Html.RenderPartial("ProductSummary", p); <p>@Html.ActionLink("Details...", "Details", "Product", new { p.ProductID }, null)</p> } id总是有一个默认值=1,但我需要选择的ProductID。我做错了什么?n

在这里,我在我的ViewModel中迭代产品:

@foreach (var p in Model.Products)
{
    Html.RenderPartial("ProductSummary", p);
    <p>@Html.ActionLink("Details...", "Details", "Product", new { p.ProductID }, null)</p>
}

id
总是有一个默认值=1,但我需要选择的
ProductID
。我做错了什么?

new{p.ProductID}
将使用
ProductID
属性创建一个匿名类型

路由值必须匹配,因此使用
new{id=p.ProductID}
填充
id
参数

public ActionResult Details(int id = 1)
{
    return View();
}