繁体   English   中英

如何路由 IdentityUser 的值(如用户名)而不是整个对象?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM