C# 使用列表<;int>;在Url.Action方法中

C# 使用列表<;int>;在Url.Action方法中,c#,asp.net-mvc,razor,asp.net-mvc-routing,C#,Asp.net Mvc,Razor,Asp.net Mvc Routing,我正在为搜索页面编写代码,我必须将一些过滤器传递给操作,并根据这些输入生成超链接,因此我使用Url.action函数生成链接 下面是我的代码 @Url.Action("Index","Search",new SkillKindleWeb.ViewModels.Search.SearchRawInput() { CategoryIds = Model.Request.CategoryIds, SubCategoryIds = Model.Request.SubCategoryIds,

我正在为搜索页面编写代码,我必须将一些过滤器传递给操作,并根据这些输入生成超链接,因此我使用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

System.Collections.Generic.List%601%5BSystem.Int32%5D开始日期=03%2F30%2F2013%2000%3A00%3A00&StartPrice=0&EndPrice=140000&PageNo=2

我期望的Url是


你自己把它转换成字符串表示怎么样:

@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
})
这就是viewmodel的用途。以视图期望的方式转换和格式化所需的所有值。
请注意,我也在日期中添加了一个
ToSortDateString()
,因为您似乎对时间部分不感兴趣。

什么是
SearchRawInput
?看起来您的
列表
已转换为
字符串
开始日期
的格式不符合您的要求。您的CategoryID似乎不是单个值,而是一个列表。这就是你想要的吗?是的,我想要它给我一个像CategoryId=1&CategoryId=2SearchRawInput是一个视图这样的字符串model@rajansoft1首先,你应该在你的问题中加入你上面非常有用的评论。我没有想到你真正想要的是什么。当我的列表为空时会发生什么?如果你的列表为空(意味着计数=0),则生成的字符串是空字符串。