您可以創建自定義ModelBinder
像這樣(只是參考):
public class GeoPointModelBinder : IModelBinder
{
public static Regex regex = new Regex(@"^geoPoints\[\(d+)\]\[(longitude|latitude)\]$", RegexOptions.IgnoreCase);
public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext)
{
var query = actionContext.Request.RequestUri.Query;
var parameters = query
.Split(new char[] { '&' }, StringSplitOptions.RemoveEmptyEntries)
.Select(it => it.Split('='))
.Where(it => regex.IsMatch(it[0]))
.ToDictionary(it => it[0], it => it[1]);
var points = parameters
.Select(it => new GeoPoint())
.ToList();
foreach (var parameter in parameters)
{
var match = regex.Match(parameter.Key);
var firstGroup = match.Groups[1];
var secondGroup = match.Groups[2];
int index = int.Parse(firstGroup.Value);
string field = secondGroup.Value;
if (string.Equals(field, "latitude", StringComparison.OrdinalIgnoreCase))
{
points[index].Latitude = parameter.Value;
}
else
{
points[index].Longitude = parameter.Value;
}
}
bindingContext.Model = points;
return true;
}
}
...
[HttpGet]
public HttpResponseMessage Test([ModelBinder(typeof(GeoPointModelBinder))]List<GeoPoint> geoPoints)
{
//...
}
什麼技術是什麼?請 - 相應地標記您的問題。 –
我是sory。 ASP.NET .net framework 4.5.1 – repu
除非你創建一個自定義的'ModelBinder' –