我的控制器正在使用路由属性,如下所示
[Route("tenant/{tenantId}/store/edit/{id}")]
public ActionResult Edit(int tenantId, int id)
{
...
}
@Html.ActionLink("Edit", "Edit", "Store", new { tenantId = Request.QueryString["tenantId"], id = item.Id}, null)
我希望ActionLink生成的网址看起来像http://localhost/tenant/1/store/edit/3
,但它会产生类似http://localhost/store/edit/3?tenantId=1
的内容
答案 0 :(得分:1)
找到答案,因为我已经从“租户”控制器编辑了前一个,我不再使用查询字符串来获取tenantId。
相反,现在我正在使用
var tId = ViewContext.RouteData.Values["tenantId"];
并且更新的ActionLink看起来应该是这样的
Html.ActionLink("Edit", "Edit", "Store", new { tenantId = tId, id = item.Id}, null)