Asp.net mvc MVC路由-如果我输入参数id,则出现异常

Asp.net mvc MVC路由-如果我输入参数id,则出现异常,asp.net-mvc,Asp.net Mvc,我需要使用MVC路由将产品id放入(ProductDetails页面)中的url中。 如果没有id参数,一切正常,但是如果我输入id,我会得到这个异常 “/”应用程序中出现服务器错误。 参数字典包含“OnlineCarStore.Controllers.ProductController”中方法“System.Web.Mvc.ActionResult子类别(System.String、Int32、System.String、System.String、System.String)”的非null类

我需要使用MVC路由将产品id放入(ProductDetails页面)中的url中。 如果没有id参数,一切正常,但是如果我输入id,我会得到这个异常

“/”应用程序中出现服务器错误。 参数字典包含“OnlineCarStore.Controllers.ProductController”中方法“System.Web.Mvc.ActionResult子类别(System.String、Int32、System.String、System.String、System.String)”的非null类型“System.Int32”的参数“id”的null条目。可选参数必须是引用类型、可为null的类型或声明为可选参数。 参数名称:参数 描述:执行当前web请求期间发生未处理的异常。请查看堆栈跟踪以了解有关错误的更多信息以及错误在代码中的起源

这就是我的观点:

  <a href="@Url.Action("ProductDetails", "Product" , new {supplierName = c.SupplierName.Replace(" ", "-"), code = productCode, name = name.Replace("---", "-"), prodId=c.ProductId })" id="link">
     Details
  </a>    

你能告诉我是什么问题吗?正如我所说,没有prodId参数,一切都很好。提前谢谢

错误消息显示您正在调用
子类别
方法。应用于该方法的签名和
Route
属性是什么(它首先与该方法匹配)?我在子类别中使用此路由方法:[Route({selected}/{category}/{id}/{engineId}”)]公共操作结果子类别(string selected,int id,string category,string engineId){您需要编辑带有相关详细信息的问题。这与您在
ProductDetails
方法上的路线相同(即它包含4个段),您需要区分它们-例如
[路线(“产品/ProductDetails/{supplierName}/{code}/{name}/{prodId}”)]
但在url中,我不应该显示控制器和actin方法名称:Product/ProductDetails。这就是我之所以这样说的原因。你需要一些东西来区分你的路线!
  <a href="@Url.Action("ProductDetails", "Product" , new {supplierName = c.SupplierName.Replace(" ", "-"), code = productCode, name = name.Replace("---", "-"), prodId=c.ProductId })" id="link">
     Details
  </a>    
 [Route("{supplierName}/{code}/{name}/{prodId}")]
 public ActionResult ProductDetails(string supplierName, string code, string name, string prodId)
 {...}