[英]How do I route a value of an IdentityUser (like Username) and not the entire object?
So my View looks like this:所以我的视图看起来像这样:
@model List<ListUsers>
<div class="card-deck">
@foreach (var user in Model)
{
<div class="card m-3" style="min-width: 18rem; max-width:30.5%">
<div class="card-header">
<h5>@user.FriendId</h5>
</div>
<div class="card-body">
<h2>@user.FriendName</h2>
</div>
<div class="card-footer text-center">
<a asp-controller="account" asp-action="showprofile" asp-route-id="@user"
class="btn btn-primary">ShowProfile</a>
</div>
</div>
}
</div>
Even if I write即使我写
"asp-route-id="@user.FriendId"
(and I can see in the source code of the page in the browser that the ID is appended in the url) it hands the entire IdentityUser Object to the corresponding actionmethod. (我可以在浏览器页面的源代码中看到,该 ID 附加在 url 中)它将整个 IdentityUser 对象交给相应的操作方法。 I just want the string.
我只想要字符串。
This doesn't work either.这也行不通。
"asp-route-id="@user.FriendId.ToString()"
Thank you!谢谢!
First confirm the field type of FriendId, receive the same type
of parameter in the showprofile action, and receive the parameter with "id"
variable name.首先确认FriendId的字段类型,在showprofile action中接收
same type
参数,接收带有"id"
变量名的参数。
public IActionResult showprofile(int id)//if it is string type,use 'string id' to receive
{
// do what you want
return View();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.