【问题标题】:how to get the username value from url in asp.net如何从asp.net中的url获取用户名值
【发布时间】:2021-12-27 12:26:27
【问题描述】:

我想从 URL 获取用户名,我在按钮单击 URL 更改时附上图片我想在变量中获取用户名值。请帮帮我

<table class="table table-bordered table-striped">
    <tr>
        <th>
            User
        </th>
    </tr>

    @foreach (User item in Model.user_get)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.UserName)
                <input type="button" value="Add User" onclick="location.href='@Url.Action($"Create/username={item.UserName}", "addgroupmember")'" />
                 
            </td>


        </tr>
    }

</table>


   

            public ActionResult Create()
            {
                dynamic dy = new ExpandoObject();

                dy.user_get = get_user();

                Uri MyUrl = Request.Url;
                Console.WriteLine(MyUrl);
                string name = Request.QueryString["username"];



                List<string> selectedUsers = new List<string>();
                selectedUsers.Add(name);
                return View(dy);
        }

enter image description here

【问题讨论】:

    标签: asp.net asp.net-mvc asp.net-mvc-3


    【解决方案1】:
    var qsArray = Request.QueryString.AllKeys.Select(key => new { Name = key.ToString(), Value = Request.QueryString[key.ToString()] }).Where(a => !string.IsNullOrEmpty(a.Value)).ToArray();
    var UserName= qsArray.Where(a => a.Name == "username").Select(a => a.Value).ElementAt(0);
    

    【讨论】:

      猜你喜欢
      • 2011-03-17
      • 1970-01-01
      • 1970-01-01
      • 2020-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-25
      • 2011-02-24
      相关资源
      最近更新 更多