【发布时间】:2018-12-11 06:57:48
【问题描述】:
我在 asp.net core 中有类似的东西(我正在使用 asp.net core c# using razor):
@Html.ActionLink("Edit", "EditEmployee","Employee", new { id = item.id})
这个item.id是base64string,它将在中间层解码,它在编码字符串中有斜杠('/')字符,所以action无法理解它并且action参数为null。
我的问题是如何将此 item.id 发送到我的操作,因为它是包含斜杠('/')的 base64string。
这是我在 startup.cs 中的地图路线:
routes.MapRoute(
name: "EditEmployee",
template: "{controller=Employee}/{action=EditEmployee}/{id?}");
这是我需要调用的操作...但是双斜杠参数正在变为空。
[HttpGet]
[ActionName("EditEmployee")]
public async Task<IActionResult> EditEmployee(string id)
{
if (!string.IsNullOrEmpty(id))
{
var result = await _accountAction.GetEditEmployee(id);
if (result.Item1)
{
return View(result.Item2);
}
}
return RedirectToAction(nameof(ListEmployee));
}
【问题讨论】:
-
加密工作正常,但我的控制器不接受这个多斜线数据作为参数。
-
我的意思是为什么不使用
WebUtility.UrlDecode,将你的cshtml行改为这个-@Html.ActionLink("Edit", "EditEmployee","Employee", new { id = System.Net.WebUtility.UrlDecode(item.id) })