【发布时间】:2010-02-12 17:40:06
【问题描述】:
我有一个带有 DateTime 搜索条件以及其他一些条件的搜索表单:
<form method="get" action="/app/search">
<input type="text" value="13/01/2010" name="BeginDate"/>
<input type="text" value="blah" name="SomeOtherCriterion"/>
<form>
所以我有一个带有默认操作(我们称之为索引)和 SearchCriteria 参数的搜索控制器。
public class SearchController
{
public ActionResult Index(SearchCriteria searchCriteria) {//blah }
}
public class SearchCriteria
{
public DateTime BeginDate {get; set;}
public string SomeOtherCriterion {get; set;}
}
现在,如果我想创建一个 ActionLink,传入一个 SearchCriteria 值,那么:
Html.ActionLink("Search", "Index", searchCriteria)
我得到美国格式的 BeginDate 查询字符串参数。在 Google 上查看并在 System.Web.Routing 中使用 Reflector 似乎是因为它使用了 InvariantCulture,所以我对此无能为力。
似乎以前没有人问过这个问题,所以我想我在做一些非常愚蠢的事情......请帮忙!
编辑:将 SearchCriteria 传递给 ActionLink 而不是匿名对象,以说明为什么我不能自己执行自定义 ToString()。
【问题讨论】:
标签: asp.net-mvc