【发布时间】:2023-04-09 00:59:02
【问题描述】:
我正在为搜索页面编写代码,我必须将一些过滤器传递给操作,并且根据这些输入我必须生成超链接,因此我使用 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
})
它正在生成这样的网址
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
【问题讨论】:
-
什么是
SearchRawInput?看起来您的List<Int32>已转换为string并且StartDate的格式不符合您的要求。 -
您的 CategoryID 似乎不是单个值,而是一个列表。这就是你想要的吗?
-
是的,我希望它给我一个像 CategoryId=1&CategoryId=2 这样的字符串
-
SearchRawInput 是一个视图模型
-
@rajansoft1 您首先应该在您的问题中包含您上面那条非常有用的评论。我没有想到你真正想要什么。
标签: c# asp.net-mvc razor asp.net-mvc-routing