ASP.net MVC怎么写一个post接口接收别人传过来的json数据

懒是一种寂寞 2016-04-20 02:16:07
请求包体和请示例

我自己写的action方法,用$.post可以接收到数据,但是推送数据就是不行
...全文
1488 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Veary 2017-12-12
  • 打赏
  • 举报
回复

[HttpPost]
public void TestPost(string jsonParam)
{
    // do something ...
}
在Controller中写个方法 发布出去 别人访问这个路径 传入参数 不就好了。
gboy1988 2017-12-08
  • 打赏
  • 举报
回复
懒的无法直视
懒是一种寂寞 2016-04-20
  • 打赏
  • 举报
回复
我需要的是我写一个post的接口,别人给我推送数据,希望大牛能帮忙写一个,作为新人压力很大。
asp.net mvc 3高级编程》 第1章 入门 1 1.1 asp.net mvc简介 1 1.1.1 asp.net mvc如何适应asp.net 1 1.1.2 mvc模式简介 2 1.1.3 mvc在web框架中的应用 2 1.1.4 asp.net mvc 3的发展历程 3 1.1.5 razor视图引擎 5 1.1.6 验证的改善 8 1.1.7 强大的javascript支持 9 1.1.8 高级功能 9 1.1.9 asp.net mvc 3特性总结 10 1.2 创建asp.net mvc 3应用程序 10 1.2.1 创建asp.net mvc 3应用程序的软件要求 11 1.2.2 安装asp.net mvc 3 11 1.2.3 创建asp.net mvc 3应用程序 12 1.2.4 new asp.net mvc 3 project对话框 13 1.3 asp.net mvc应用程序的结构 17 1.4 小结 20 第2章 控制器 21 .2.1 控制器的角色 21 2.2 控制器简史 22 2.3 示例应用程序:mvc music store 23 2.4 控制器基础 26 2.4.1 简单示例:home controller 26 2.4.2 创建第一个(非常简单的)控制器 29 2.4.3 控制器操作中的参数 31 2.5 小结 33 第3章 视图 35 3.1 视图的作用 36 3.2 指定视图 38 3.3 强类型视图 39 3.4 视图模型 41 3.5 添加视图 42 3.5.1 add view对话框中的选项 42 3.5.2 自定义t4视图模板 45 3.6 razor视图引擎 46 3.6.1 razor的概念 46 3.6.2 代码表达式 48 3.6.3 html编码 50 3.6.4 代码块 51 3.6.5 razor语法示例 52 3.6.6 布局 54 3.6.7 viewstart 56 3.7 指定分部视图 57 3.8 视图引擎 58 3.8.1 配置视图引擎 58 3.8.2 查找视图 59 3.8.3 视图本身 60 3.8.4 其他的视图引擎 61 3.9 新的视图引擎还是新的actionresult 62 3.10 小结 63 第4章 模型 65 4.1 为mvc music store建模 65 4.2 为商店管理器构造基架 68 4.2.1 基架的概念 68 4.2.2 基架和实体框架 69 4.2.3 执行基架模板 71 4.2.4 执行基架代码 75 4.3 编辑专辑 78 4.3.1 创建编辑专辑的资源 79 4.3.2 响应编辑时的post请求 81 4.4 模型绑定 83 4.4.1 defaultmodelbinder 84 4.4.2 模型绑定安全性简介 85 4.4.3 显式模型绑定 85 4.5 小结 86 第5章 表单和html辅助方法 89 5.1 表单的使用 89 5.1.1 action和method特性 90 5.1.2 get方法还是post方法 90 5.2 html辅助方法 94 5.2.1 自动编码 95 5.2.2 辅助方法的使用 95 5.2.3 html辅助方法的工作原理 96 5.2.4 设置专辑编辑表单 97 5.2.5 添加输入元素 98 5.2.6 辅助方法、模型和视图数据 102 5.2.7 强类型辅助方法 104 5.2.8 辅助方法和模型元数据 105 5.2.9 模板辅助方法 105 5.2.10 辅助方法和modelstate 106 5.3 其他输入辅助方法 107 5.3.1 html.hidden 107 5.3.2 html.password 107 5.3.3 html.radiobutton 107 5.3.4 html.checkbox 108 5.4 渲染辅助方法 108 5.4.1 html.actionlink和html.routelink 109 5.4.2 url辅助方法 110 5.4.3 html.partial和html.renderpartial 110 5.4.4 html.action和html.renderaction 111 5.5 小结 113 第6章 数据注解和验证 115 6.1 为验证注解订单 116 6.1.1 验证注解的使用 117 6.1.2 自定义错误提示消息及其本地化 121 6.1.3 注解的后台原理 122 6.1.4 控制器操作和验证错误 123 6.2 自定义验证逻辑 125 6.2.1 自定义注解 125 6.2.2 ivalidatableobject 128 6.3 显示和编辑注解 129 6.3.1 display 130 6.3.2 scaffoldcolumn 130 6.3.3 displayformat 131 6.3.4 readonly 131 6.3.5 datatype 132 6.3.6 uihint 132 6.3.7 hiddeninput 132 6.4 小结 132 第7章 应用程序的安全性 133 7.1 使用authorize特性登录 135 7.1.1 保护控制器操作 135 7.1.2 authorize特性在表单身份验证、accountcontroller控制器中的用法 139 7.1.3 intranet application模板中的windows authentication 141 7.1.4 整个控制器的安全性 141 7.2 要求角色成员使用authorize特性 142 7.3 扩展角色和成员 143 7.4 web应用程序中的安全向量 143 7.4.1 威胁:跨站脚本 144 7.4.2 威胁:跨站请求伪造 154 7.4.3 威胁:cookie盗窃 158 7.4.4 威胁:重复提交 160 7.4.5 威胁:开放重定向 162 7.5 适当的错误报告和堆栈跟踪 170 7.5.1 使用配置转换 171 7.5.2 使用retail部署配置 172 7.5.3 使用专门的错误日志系统 172 7.6 安全回顾和有用资源 172 7.7 小结 173 第8章 ajax 175 8.1 jquery 175 8.1.1 jquery的特性 176 8.1.2 非侵入式javascript 179 8.1.3 jquery的用法 180 8.2 ajax辅助方法 183 8.2.1 ajax的actionlink方法 183 8.2.2 html 5特性 185 8.2.3 ajax表单 186 8.3 客户端验证 188 8.3.1 jquery验证 189 8.3.2 自定义验证 190 8.4 辅助方法之外 194 8.4.1 jquery ui 194 8.4.2 使用jquery ui实现自动完成部件 195 8.4.3 json和jquery模板 199 8.5 提高ajax性能 204 8.5.1 使用内容分发网络 204 8.5.2 脚本优化 204 8.6 小结 205 第9章 路由机制 207 9.1 理解url 208 9.2 路由机制概述 209 9.2.1 对比路由和url重 209 9.2.2 路由的定义 209 9.2.3 命名路由 217 9.2.4 mvc区域 219 9.2.5 catch-all参数 220 9.2.6 段中的多个url参数 221 9.2.7 stoproutinghandler和ignoreroute 222 9.2.8 路由的调试 223 9.2.9 揭秘路由如何生成url 224 9.3 揭秘路由如何绑定到操作 230 9.3.1 高层次请求的路由管道 230 9.3.2 路由数据 230 9.4 自定义路由约束 231 9.5 web forms和路由机制 232 9.6 小结 233 第10章 nuget 235 10.1 nuget概述 235 10.2 nuget安装 236 10.3 以包的形式添加库 238 10.3.1 查找包 239 10.3.2 安装包 240 10.3.3 更新包 242 10.3.4 最近使用的包 243 10.4 创建包 245 10.4.1 文件夹结构 246 10.4.2 nuspec文件 246 10.4.3 元数据 247 10.4.4 依赖库 248 10.4.5 指定要包含的文件 249 10.4.6 工具 249 10.4.7 框架和轮廓定位 252 10.5 发布包 253 10.5.1 发布到nuget.org 253 10.5.2 使用nuget.exe发布包 256 10.5.3 包浏览器的用法 257 10.5.4 托管私有的nuget供应库 258 10.6 小结 261 第11章 依赖注入 263 11.1 软件设计模式概述 263 11.1.1 设计模式—— 控制反转模式 264 11.1.2 设计模式—— 服务定位器 266 11.1.3 设计模式—— 依赖注入 270 11.2 依赖解析器的用法 272 11.2.1 单一注册服务 274 11.2.2 复合注册服务 275 11.2.3 创建任意对象 278 11.3 小结 280 第12章 单元测试 281 12.1 单元测试和测试驱动开发的意义 282 12.1.1 单元测试的定义 282 12.1.2 测试驱动开发的定义 283 12.2 创建单元测试项目 286 12.2.1 检查默认单元测试 287 12.2.2 只测试自己编的代码 290 12.3 单元测试用于asp.net mvc应用程序的技巧和窍门 291 12.3.1 控制器测试 291 12.3.2 路由测试 296 12.3.3 验证测试 298 12.4 小结 302 第13章 扩展asp.net mvc 303 13.1 模型扩展 304 13.1.1 把请求数据转化为模型 304 13.1.2 用元数据描述模型 309 13.1.3 验证模型 312 13.2 视图扩展 315 13.2.1 自定义视图引擎 315 13.2.2 编html辅助方法 317 13.2.3 编razor辅助方法 319 13.3 控制器扩展 319 13.3.1 操作选择 319 13.3.2 操作过滤器 321 13.3.3 提供自定义结果 323 13.4 小结 324 第14章 高级主题 325 14.1 高级razor 325 14.1.1 模板化的razor委托 325 14.1.2 视图编译 326 14.2 高级基架 328 14.2.1 自定义t4代码模板 328 14.2.2 nuget包mvcscaffolding 329 14.2.3 更新的add controller对话框选项 329 14.2.4 使用库模板 330 14.2.5 添加基架器 332 14.2.6 额外资源 332 14.3 高级路由 332 14.3.1 routemagic 332 14.3.2 可编辑的路由 333 14.4 模板 337 14.4.1 默认模板 338 14.4.2 自定义模板 342 14.5 高级控制器 344 14.5.1 定义控制器:icontroller接口 344 14.5.2 controllerbase抽象基类 346 14.5.3 控制器类和操作 346 14.5.4 actionresult 351 14.5.5 操作调用器 359 14.5.6 使用异步控制器操作 362 14.6 小结 370
AspNetMVC2_RC_VS2008.exe ASP.NET MVC 2 Release Candidate Release Notes This document describes the Release Candidate release of the ASP.NET MVC 2 framework. Installation Notes 2 Documentation 2 Support 2 Upgrading an ASP.NET MVC 1.0 Project to ASP.NET MVC 2 2 New Features 3 ASP.NET MVC validation scripts have been moved to their own file 4 ASP.NET MVC validation scripts can be included at the top or bottom of a page 4 ASP.NET MVC validation scripts support globalization 4 Html.ValidationSummary helper method can display model-level errors 4 T4 templates in Visual Studio generate code that is specific to the target version of the .NET Framework 4 Other Improvements 4 Bug Fixes 5 Breaking Changes 5 Changes in ASP.NET MVC 2 Release Candidate 5 Changes in ASP.NET MVC 2 Beta 6 Changes in ASP.NET MVC 2 Preview 2 6 Changes in ASP.NET MVC 2 Preview 1 7 Known Issues 7 Disclaimer 8 This document describes the Release Candidate release of ASP.NET MVC 2 for Visual Studio 2008 SP1. Installation Notes The ASP.NET MVC 2 Release Candidate for Visual Studio 2008 SP1 can be downloaded from the following page: http://go.microsoft.com/fwlink/?LinkID=157071 ASP.NET MVC 2 can be installed and can run side-by-side with ASP.NET MVC 1.0. Note   Because Visual Studio 2008 and Visual Studio 2010 Beta 2 share a component of ASP.NET MVC 2, installing the ASP.NET MVC 2 Release Candidate release on a computer where Visual Studio 2010 Beta 2 is also installed is not supported. Documentation Documentation for ASP.NET MVC 2, which includes tutorials, technology overviews, code samples, and API reference, is available on the MSDN Web site. A good starting point is the ASP.NET Model View Controller (MVC) topic (http://go.microsoft.com/fwlink/?LinkId=159758). Tutorials and other information about ASP.NET MVC are also available on the ASP.NET Web site (http://www.asp.net/mvc/). Support This is a Release Candidate (RC) release and is not officially supported. If you have questions about working with this release, post them to the ASP.NET MVC forum (http://forums.asp.net/1146.aspx), where members of the ASP.NET community are frequently able to provide informal support. Upgrading an ASP.NET MVC 1.0 Project to ASP.NET MVC 2 To upgrade an existing ASP.NET MVC 1.0 application to version 2, follow these steps: Make a backup of the existing project. Open the project file in a text editor (the file with the .csproj or .vbproj file extension) and find the ProjectTypeGuid element. As the value of that element, replace the GUID {603c0e0b-db56-11dc-be95-000d561079b0} with {F85E285D-A4E0-4152-9332-AB1D724D3325}. When you are done, the value of that element should be as follows: {F85E285D-A4E0-4152-9332-AB1D724D3325};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} In the Web application root folder, edit the Web.config file. Search for System.Web.Mvc, Version=1.0.0.0 and replace all instances with System.Web.Mvc, Version=2.0.0.0. Repeat the previous step for the Web.config file located in the Views directory. Open the project using Visual Studio, and in Solution Explorer, expand the References node. Delete the reference to System.Web.Mvc (which points to the version 1.0 assembly). Add a reference to System.Web.Mvc (v2.0.0.0). Add the following bindingRedirect element to the Web.config file in the application root under the configuraton section: Create a new ASP.NET MVC 2 application. Copy the files from the Scripts directory of the new application into the Scripts directory of the existing application. Compile the application and run it. If any errors occur, refer to the Breaking Changes section of this document for possible solutions. New Features This section describes features that have been introduced in the ASP.NET MVC 2 Release Candidate release. ASP.NET MVC validation scripts have been moved to their own file To help reduce conflicts with other Ajax libraries, the built-in ASP.NET MVC validation scripts are now in a separate JavaScript file. ASP.NET MVC validation scripts can be included at the top or bottom of a page The server component that renders the client validation metadata now renders the metadata into a JavaScript variable. This allows the validation scripts to be included either at the top of the page or at the bottom, because the scripts will look for the variable and load the metadata when it is available. ASP.NET MVC validation scripts support globalization When the required ASP.NET Ajax globalization scripts are included in a page, the validation logic uses the culture-specific data for data types (such as dates and numbers) when it validates input text. The new Html.GlobalizationScript helper method can be used to render a reference to the globalization script for the current culture. Html.ValidationSummary helper method can display model-level errors Instead of always displaying all validation errors, the Html.ValidationSummary helper method has a new option to display only model-level errors. This enables model-level errors to be displayed in the validation summary and field-specific errors next to each field. T4 templates in Visual Studio generate code that is specific to the target version of the .NET Framework A new property is available to T4 files from the ASP.NET MVC T4 host that specifies the version of the .NET Framework that is used by the application. This allows T4 templates to generate code and markup that is specific to a version of the .NET Framework. In Visual Studio 2008, the value is always .NET 3.5. In Visual Studio 2010, the value is either .NET 3.5 or .NET 4. Other Improvements The following additional changes have been made to existing types and members for the ASP.NET MVC 2 Release Candidate release. The default HTML markup that is generated by the Add View dialog box has been changed to be consistent with the markup that is rendered by the templated helpers (Editor, EditorFor, Display, and DisplayFor). Buttons in a form can specify that they do not cause validation logic to run. The default is that every button in a form causes validation logic to run, and if validation fails, the validation logic blocks submission of the form. Enabling validation selectively for buttons lets you create forms that can post information even if a form is not complete or if the form contains data that is temporarily invalid. Client validators can specify when they run. Possible values are input (while the user is typing), blur (after the user is done typing and moves to another field), and submit (when the user submits the form). Bug Fixes The following bugs have been fixed in the ASP.NET MVC 2 Release Candidate release. The FileResult action result now supports non-US-ASCII characters in file names. Methods and properties of the TempDataDictionary class have been improved to better handle the case when items are flagged for removal from the dictionary. Support for validation in the IDataErrorInfo interface has been fixed. Breaking Changes The following changes might cause errors in existing ASP.NET MVC 1.0 applications. Changes in ASP.NET MVC 2 Release Candidate IIS script mapping script is no longer available in the installer The IIS script mapping script is a command-line script that is used to configure script maps for IIS 6 and for IIS 7 in Classic mode. The script-mapping script is not needed if you use the Visual Studio Development Server or if you use IIS 7 in Integrated mode. The scripts are available as a separate unsupported download on the ASP.NET CodePlex site. The Html.Substitute helper method in MVC Futures is no longer available Due to changes in the rendering behavior of MVC view engines, the Html.Substitute helper method does not work and has been removed. Changes in ASP.NET MVC 2 Beta The IValueProvider interface replaces all uses of IDictionary Every property or method argument that accepted IDictionary now accepts IValueProvider. This change affects only applications that include custom value providers or custom model binders. Examples of properties and methods that are affected by this change include the following: The ValueProvider property of the ControllerBase and ModelBindingContext classes. The TryUpdateModel methods of the Controller class. New CSS classes were added in the Site.css file that are used to style validation messages. Changes in ASP.NET MVC 2 Preview 2 Helpers now return an MvcHtmlString object In order to take advantage of the new HTML-encoding expression syntax in ASP.NET 4, the return type for HTML helpers is now MvcHtmlString instead of a string. Note that if you use ASP.NET MVC 2 and the new helpers with ASP.NET 3.5, you will not be able to take advantage of the HTML-encoding syntax; the new syntax is available only when you run ASP.NET MVC 2 on ASP.NET 4. JsonResult now responds only to HTTP POST requests In order to mitigate JSON hijacking attacks that have the potential for information disclosure, by default, the JsonResult class now responds only to HTTP POST requests. Ajax GET calls to action methods that return a JsonResult object should be changed to use POST instead. If necessary, you can override this behavior by setting the new JsonRequestBehavior property of JsonResult. For more information about the potential exploit, see the blog post JSON Hijacking on Phil Haack’s blog. Model and ModelType property setters on ModelBindingContext are obsolete A new settable ModelMetadata property has been added to the ModelBindingContext class. The new property encapsulates both the Model and the ModelType properties. Although the Model and ModelType properties are obsolete, for backward compatibility the property getters still work; they delegate to the ModelMetadata property to retrieve the value. Changes in ASP.NET MVC 2 Preview 1 Changes to the DefaultControllerFactory class break custom controller factories that derive from it The DefaultControllerFactory class was fixed by removing the RequestContext property. In place of this property, the request context instance is passed to the protected virtual GetControllerInstance and GetControllerType methods. This change affects custom controller factories that derive from DefaultControllerFactory. Custom controller factories are often used to provide dependency injection for ASP.NET MVC applications. To update the custom controller factories to support ASP.NET MVC 2, change the method signature or signatures to match the new signatures, and use the request context parameter instead of the property. “Area” is a now a reserved route-value key The string “area” in Route values now has special meaning in ASP.NET MVC, in the same way that “controller” and “action” do. One implication is that if HTML helpers are supplied with a route-value dictionary containing “area”, the helpers will no longer append “area” in the query string. If you are using the Areas feature, make sure to not use {area} as part of your route URL. Known Issues Adding a debugger watch that shows a value from TempData will mark it for deletion. The side effect was introduced as part of the changes to TempDataDictionary. Disclaimer This is a preliminary document and may be changed substantially prior to final commercial release of the software described herein. The information contained in this document represents the current view of Microsoft Corporation on the issues discussed as of the date of publication. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information presented after the date of publication. This White Paper is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS DOCUMENT. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation. Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property. Unless otherwise noted, the example companies, organizations, products, domain names, e-mail addresses, logos, people, places and events depicted herein are fictitious, and no association with any real company, organization, product, domain name, email address, logo, person, place or event is intended or should be inferred. © 2009 Microsoft Corporation. All rights reserved. Microsoft and Windows are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. The names of actual companies and products mentioned herein may be the trademarks of their respective owners.

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧