asp.net-mvc C ASP.NET MVC中的WebApi [FromUri]是什么?
尽管从2.0开始就使用MVC,但我从来没有使用过这个网站(d
|
在WebApi中,我可以使用[FromUri]在控制器操作上装饰一个参数,使URI成为“反序列化”的组件,如果您将进入POCO模型;又称模型绑定. 尽管从2.0开始就使用MVC,但我从来没有使用过这个网站(dunno为什么).在ASP.NET MVC 5中相当于什么? 该属性似乎在IDE中似乎不被识别,除非我需要引用一个库. 我想要/ thing / 2014/9绑定到下面的模型: public class WhateverModel { public int Year { get; set; } public int Month { get; set; } }谢谢 更新 在另一个问题(上面的链接)中,OP说: 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 这意味着他正在使用WebApi的属性.我猜.我没有这些引用,因为我在MVC中,(ab)使用WebApi的版本是MVC中接受的方法吗? 更新2 在这个问题的答案是: You need to construct your query string respecting MVC model binder naming conventions. Additionally [FromUri] attribute in your example action is completely ignored,since it’s not known to MVC DefaultModelBinder 所以我仍然不知道OP在这个问题上甚么谈论该做什么,甚至在地球上,如果他在错误的属性上取得了一些成功. 我想我希望有一个明确的答案,而不是另一个问题的泥土. 解决方法 它会工作? [HttpGet] public ActionResult Thing(WhateverModel model) { // use model return View(); }至少在使用URL /东西?年= 2014和月= 9. 问题是你的路由. URL / thing / 2014/9将不会使用MVC的默认路由映射,因为/ {controller} / {action} / {id},其中{id}是可选的int. 最简单的方法是使用属性路由: [HttpGet] [Route("/thing/{Year}/{Month}"] public ActionResult Thing(WhateverModel model) { // use model return View(); }这将URL映射到您的模型. (编辑:日照站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net-mvc – 单元测试中的ViewResult.ViewName属性为空
- ASP.NET -- WebForm -- 页面生命周期事件
- 在ASP.Net网站上使用WCF服务的教程?
- 是否有WPF的母版页(如asp.net)的概念?
- 为什么私有事件处理程序在ASP.NET中不起作用
- asp.net – 无法加载文件或程序集App_Licenses
- asp.net-mvc – AJAX POST到MVC Controller显示302错误
- asp.net-mvc – MVC 3布局页面,Razor模板和下拉列表
- 看美剧英文字幕学英语的利器深蓝英文字幕助手简介
- asp.net-mvc-3 – 为MVC3应用程序配置Ninject的正确方法是什
- .NET 3.5 / VS 2008上的ASP.NET Web Services的自
- asp.net-mvc – 在Controller操作方法中重用代码
- asp.net-core – 在执行DI时指定服务选项的干净方
- asp.net – 适用于多个用户的EWS通知中心
- 学习:正则表达式的基本语法
- asp.net-mvc-3 – 用于在ASP.NET MVC3中使用Grid
- asp.net-mvc – 隐藏日期时间的ASP.NET MVC格式
- asp.net-mvc – 如何组合两个dataTextFields的Se
- asp.net-mvc – 控制器操作无法从JSON读取Guid P
- asp.net-mvc – Url.Action生成查询字符串,以任何
