您是说,在您的客户控制器上,您希望能够将任何值或 customerid 传递给返回索引页面的索引操作吗?
假设您没有更改默认路由,您可以更改控制器操作以接受可为空的 int,然后根据 customerid 是否为空来获取模型:
public ActionResult Index(int? customerid)
{
YourModelType model;
if (customerid == null)
{
model = /* however you get your model when you don't have an id */
}
else
{
model = /* however you get your model when you have an id */;
}
return View("Index", model);
}
您还需要更新路由引擎以接受可选的 customerid 参数:
routes.MapRoute(
"Customer", // Route name
"Customer/{action}/{customerid}", // URL with parameters
new { controller = "Customer", action = "Index", customerid = UrlParameter.Optional } // Parameter defaults
);