带有 ViewModel 的 RouteValues
我有一个 ViewModel,它是一个非常简单的过滤器对象,如下所示:
public class FilterViewModel
{
public String FilterTerm { get; set; }
public String FilterProperty { get; set; }
}
我希望做的是从另一个页面到此页面的路由链接,并将我的 FilterViewModel 传递到 RouteValues 的路由 url 创建中,如下所示:
Url.RouteUrl("myRoute", new { filter = new FilterViewModel() { FilterProperty = "Product", FilterTerm = _detail.FilterTerm }})"
Lo,什么另一方面呈现的是
http://theurl?filter=Fully.Qualified.Namespace.FilterViewModel
我不知道我期望什么,也许是序列化到查询字符串中的东西,如下所示:
http://theurl?filter=FilterProperty|Product,FilterTerm|ProductA
是否有办法做我想做的开箱即用的事情? (或者不是开箱即用的)
I have a ViewModel that is a very simple filter object like this:
public class FilterViewModel
{
public String FilterTerm { get; set; }
public String FilterProperty { get; set; }
}
what I was hoping to do was to do a route link from another page into this one and pass my FilterViewModel into the route url creation into the RouteValues like this:
Url.RouteUrl("myRoute", new { filter = new FilterViewModel() { FilterProperty = "Product", FilterTerm = _detail.FilterTerm }})"
Lo, what renders on the other side is
http://theurl?filter=Fully.Qualified.Namespace.FilterViewModel
I don't know what I expected, perhaps something that's serialized into the query string like this:
http://theurl?filter=FilterProperty|Product,FilterTerm|ProductA
Is there anyway to do what I'm trying to do out of the box? (or not out of the box)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这样:
不知道您的路由配置是什么样子,但这可能会产生
http://theurl?FilterProperty=Product&FilterTerm=ProductA
行中的内容。对于任何更奇特的东西,比如您在问题中显示的网址,您将必须编写自定义帮助程序。这没什么标准的。Try like this:
No idea how your routing configuration looks like but this might produce something among the lines of
http://theurl?FilterProperty=Product&FilterTerm=ProductA
. For anything more exotic like the urls you have shown in your question you will have to write custom helpers. It's nothing standard.