Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 对数组使用asp route-{variable}标记帮助程序_C#_Asp.net Core_Razor Pages - Fatal编程技术网

C# 对数组使用asp route-{variable}标记帮助程序

C# 对数组使用asp route-{variable}标记帮助程序,c#,asp.net-core,razor-pages,C#,Asp.net Core,Razor Pages,我正在从中学习,并努力使其适应我的需要。对于分页链接,缩短为: <a asp-page="./Index" asp-route-pageIndex="@(Model.Student.PageIndex + 1)" asp-route-currentFilter="@Model.CurrentFilter" class="btn btn-default"> Next </a> 它以字符串数组的形式进入我的模型。我找不到任何关于如何使用asp ro

我正在从中学习,并努力使其适应我的需要。对于分页链接,缩短为:

<a asp-page="./Index"
   asp-route-pageIndex="@(Model.Student.PageIndex + 1)"
   asp-route-currentFilter="@Model.CurrentFilter"
   class="btn btn-default">
    Next
</a>

它以字符串数组的形式进入我的模型。我找不到任何关于如何使用asp route tag helper将数组传递到查询字符串的文档或解决方案。

在得到一个很好的答案之前,我一直在做的黑客感觉的工作

我已经更新了CSHTML以使用asp所有路由数据

@{
    var nextParms = new Dictionary<string, string>();

    int x = 0;
    nextParms.Add("pageIndex", (Model.Mini.PageIndex + 1).ToString());
    foreach (string item in Model.CurrentFilter)
    {
        nextParms.Add("SearchString" + x, item);
        x++;
    }
}

<a asp-page="./Index"
   asp-all-route-data="nextParms"
   class="btn btn-default">
    Next
</a>
@{
var nextParms=新字典();
int x=0;
添加(“pageIndex”,(Model.Mini.pageIndex+1.ToString());
foreach(Model.CurrentFilter中的字符串项)
{
添加(“搜索字符串”+x,项);
x++;
}
}
下一个
然后,如果在OnGet方法中有CurrentFilterN而没有CurrentFilter,我将重建CurrentFilter

        if (CurrentFilter !=null && CurrentFilter .Count()>0)
        {
            //Logic if CurrentFilter exists as normal
        }
        else
        {
           List<string> SearchList = new List<string>();

            foreach (var key in HttpContext.Request.Query)
            {
                if (key.Key.Contains("SearchString"))
                {
                    SearchList.Add(key.Value);
                    string IndividualTag = key.Value;
                }
                //Same logic as above
            }

            CurrentFilter = SearchList.ToArray();
        }
if(CurrentFilter!=null&&CurrentFilter.Count()>0)
{
//如果CurrentFilter正常存在,则为逻辑
}
其他的
{
列表搜索列表=新列表();
foreach(HttpContext.Request.Query中的var键)
{
if(key.key.Contains(“SearchString”))
{
SearchList.Add(key.Value);
string IndividualTag=key.Value;
}
//逻辑同上
}
CurrentFilter=SearchList.ToArray();
}
因此,如果用户使用multiselect,CurrentFilter将正确设置。如果他们点击next,SearchString0,SearchString1,…,SearchStringN将在解析为CurrentFilter的查询字符串中传递


感觉很粗糙,但很有效。

我最后把值放在逗号分隔的字符串上,然后使用
string.Split(',')。选择(s=>int.Parse(s))

        if (CurrentFilter !=null && CurrentFilter .Count()>0)
        {
            //Logic if CurrentFilter exists as normal
        }
        else
        {
           List<string> SearchList = new List<string>();

            foreach (var key in HttpContext.Request.Query)
            {
                if (key.Key.Contains("SearchString"))
                {
                    SearchList.Add(key.Value);
                    string IndividualTag = key.Value;
                }
                //Same logic as above
            }

            CurrentFilter = SearchList.ToArray();
        }