gpt4 book ai didi

c# - 在 Url.Action 方法中使用 List

转载 作者:太空宇宙 更新时间:2023-11-03 10:58:49 26 4
gpt4 key购买 nike

我正在为搜索页面编写代码,我必须将一些过滤器传递给操作,并且根据这些输入我必须生成超链接,因此我使用 Url.Action 函数生成链接。

下面是我的代码

@Url.Action("Index","Search",new SkillKindleWeb.ViewModels.Search.SearchRawInput()
{
CategoryIds = Model.Request.CategoryIds,
SubCategoryIds = Model.Request.SubCategoryIds,
StartDate = Model.Request.StartDate,
EndDate = Model.Request.EndDate,
StartPrice = Model.Request.StartPrice,
LocationGroupIds = Model.Request.LocationGroupIds,
LocationIds = Model.Request.LocationIds,
EndPrice = Model.Request.EndPrice,
City = Model.Request.City,
PageNo = 1,
SearchQuery = Model.Request.SearchQuery,
Segment1 = Model.Request.Segment1,
Segment2 = Model.Request.Segment2,
TargetAge = Model.Request.TargetAge
})

它正在生成这样的 url

http://someDomain.com/ncr/classes?CategoryIds= System.Collections.Generic.List%601%5BSystem.Int32%5D&StartDate=03%2F30%2F2013%2000%3A00%3A00&StartPrice=0&EndPrice=140000&PageNo=2

我预期的网址是

http://SomeDomain.com/ncr/classes?CategoryIds=9&StartDate=3/30/2013&StartPrice=0&EndPrice=140000

最佳答案

像这样自己将其转换为字符串表示怎么样:

@Url.Action("Index","Search",new SkillKindleWeb.ViewModels.Search.SearchRawInput()
{
CategoryIds = string.Join(",", Model.Request.CategoryIds),
SubCategoryIds = string.Join(",", Model.Request.SubCategoryIds),
StartDate = Model.Request.StartDate.ToShortDateString(),
EndDate = Model.Request.EndDate.ToShortDateString(),
StartPrice = Model.Request.StartPrice,
LocationGroupIds = Model.Request.LocationGroupIds,
LocationIds = Model.Request.LocationIds,
EndPrice = Model.Request.EndPrice,
City = Model.Request.City,
PageNo = 1,
SearchQuery = Model.Request.SearchQuery,
Segment1 = Model.Request.Segment1,
Segment2 = Model.Request.Segment2,
TargetAge = Model.Request.TargetAge
})

这就是 View 模型的用途。您以 View 期望的方式转换和格式化所有需要的值。请注意,我还向您的日期添加了 ToShortDateString(),因为您似乎对时间部分不感兴趣。

关于c# - 在 Url.Action 方法中使用 List<int>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18462242/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com