[英]How do I route a value of an IdentityUser (like Username) and not the entire object?
所以我的視圖看起來像這樣:
@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>
即使我寫
"asp-route-id="@user.FriendId"
(我可以在瀏覽器頁面的源代碼中看到,該 ID 附加在 url 中)它將整個 IdentityUser 對象交給相應的操作方法。 我只想要字符串。
這也行不通。
"asp-route-id="@user.FriendId.ToString()"
謝謝!
首先確認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.