尽管从2.0开始就使用MVC,但我从来没有使用过这个网站(dunno为什么).在ASP.NET MVC 5中相当于什么?@H_301_3@
该属性似乎在IDE中似乎不被识别,除非我需要引用一个库.@H_301_3@
我想要〜/ thing / 2014/9绑定到下面的模型:@H_301_3@
public class WhateverModel { public int Year { get; set; } public int Month { get; set; } }
谢谢@H_301_3@
更新@H_301_3@
However,switch this to plain MVC not WebApi and the default model binder breaks down and cannot bind the properties on objects in the nested array@H_301_3@
这意味着他正在使用WebApi的属性.我猜.我没有这些引用,因为我在MVC中,(ab)使用WebApi的版本是MVC中接受的方法吗?@H_301_3@
更新2@H_301_3@
在这个问题的答案是:@H_301_3@
You need to construct your query string respecting MVC model binder naming conventions.@H_301_3@
Additionally
[FromUri]
attribute in your example action is completely ignored,since it’s not known to MVC DefaultModelBinder@H_301_3@
所以我仍然不知道OP在这个问题上甚么谈论该做什么,甚至在地球上,如果他在错误的属性上取得了一些成功.@H_301_3@
我想我希望有一个明确的答案,而不是另一个问题的泥土.@H_301_3@
解决方法
[HttpGet] public ActionResult Thing(WhateverModel model) { // use model return View(); }
至少在使用URL /东西?年= 2014和月= 9.@H_301_3@
问题是你的路由. URL / thing / 2014/9将不会使用MVC的默认路由映射,因为/ {controller} / {action} / {id},其中{id}是可选的int.@H_301_3@
[HttpGet] [Route("/thing/{Year}/{Month}"] public ActionResult Thing(WhateverModel model) { // use model return View(); }
这将URL映射到您的模型.@H_301_3@