Asp.net MVC使用[FromUri]将url参数解析为对象 [英] Asp.net MVC parse url parameter to object using [FromUri]
问题描述
目前,我正在为一些Url-Parameter
苦苦挣扎.我尝试从以下网址创建对象:
Currently I'm struggeling with some Url-Parameter
. I try create an object from the following url:
../Data/GetOrderList?take=10&skip=0&page=1&pageSize=10&sort[0][field]=Password&sort[0][dir]=asc
除了 sort 部分之外,其余部分的效果都很好.我的方法如下:public async Task<HttpResponseMessage> GetOrderList([FromUri]Models.GridParameter model)
Which works pretty will except, the sort part. My method looks like this: public async Task<HttpResponseMessage> GetOrderList([FromUri]Models.GridParameter model)
问题是GridParameter
类,其中sort
应该是其中的属性.但是我不知道如何将这部分&sort[0][field]=Password&sort[0][dir]=asc
表示为对象.
The problem is the GridParameter
class, where sort
should be a property in. But I don't knwo how to represent this part &sort[0][field]=Password&sort[0][dir]=asc
as an object.
有人以前解决过这个问题吗?
Does someone solved this issue before?
非常感谢!
推荐答案
我假设您使用的是For ASP.NET MVC 5,不是WebAPI对吗?
最简单但不是最好的方法是在操作方法中从Request.QueryString
读取查询字符串参数.
I'm assuming you are using For ASP.NET MVC 5, not WebAPI right?
The easiest but not nicest way would be to read query string parametrs from Request.QueryString
in your action method.
You can also write your own ModelBinderAttribute class and parse Query string there, that would be much cleaner solution.
这篇关于Asp.net MVC使用[FromUri]将url参数解析为对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!