从视图映射到控制器后,如何替换 url 中的字符串或隐藏字符串?

How to replace string or hide string in url after mapping to controller from view?

我试图在从视图映射到控制器后隐藏或替换 URL 中的字符串。

查看

    <a href='@Url.Action("Product", "Index", new { prodID =@item.ProductID 
    })'>

控制器

      public ActionResult Product()
      {

        return View(model);
      }

现在我在 URL 中得到这个 http://localhost:9210/Index/Product?prodID=1 但我想要 url 这样 http://localhost:9210/Index/Product/1 那我该怎么做呢?请帮忙

你必须这样通过

<a href='@Url.Action("Product", "Index", new { id =@item.ProductID 
})'>

可能是因为 route.config 文件中定义的参数的名称是 id 而不是 prodID

您可以使用 Route 属性指定期望的路线。

[Route("Index/Product/{prodId}")]
public IHttpActionResult UpdateStatus(int prodId)
{
}