ASP.NET 5 - $.ajax post JSON.stringify(para) is null
2015-12-15 11:24
363 查看
JavaScript 代码:
Action 代码:
使用 ASP.NET 5,Action 获取到的参数都为 null,但使用之前的 ASP.NET MVC 5 是可以的,需要更改下代码:
ASP.NET 5 POST Model,需要使用 FromBody。
参考:$.ajax post JSON.stringify(para) is null
var para = {}; para.id = $("#ad-text-id").val(); para.title = $("#ad-text-title").val().trim(); para.link = $("#ad-text-link").val().trim(); $.ajax({ url: '/ajax/AdText/SaveAdText', data: JSON.stringify(para), type: 'post', dataType: 'json', contentType: 'application/json; charset=utf-8', cache: false, success: function (data) { }, error: function (xhr) { } });
Action 代码:
[HttpPost] public async Task<JsonResult> SaveAdText(int id, string title, string link) { //id, title, link para is null... }
使用 ASP.NET 5,Action 获取到的参数都为 null,但使用之前的 ASP.NET MVC 5 是可以的,需要更改下代码:
public class Model { public int Id { get; set; } public string Title { get; set; } public string Link { get; set; } } [HttpPost] public async Task<JsonResult> SaveAdText([FromBody]Model model) { //model.Id, model.Title, model.Link is not null... }
ASP.NET 5 POST Model,需要使用 FromBody。
参考:$.ajax post JSON.stringify(para) is null
相关文章推荐
- ASP.NET MVC 关闭 客户端 xss 检查
- ASPxPopupControl 关闭刷新
- ASP.NET 获取IP和MAC地址
- GridView的编辑,更新,取消,删除等功能演示
- 25、ASP.NET MVC入门到精通——Spring.net-业务层仓储
- asp.net中三层架构与mvc之区别?
- Asp.net Model binding
- 【ASP.NET】ASP.NET之数据验证控件
- ASP.NET内核几大对象、ASP.NET核心知识(6)--转载
- Encountered an unexpected error when attempting to resolve tag helper directive '@addTagHelper' with value '"*, Microsoft.AspNet.Mvc.TagHelpers"'
- 多个web.config文件按照上面顺序加载
- Windows2008 64位系统asp连接access数据库解决方法
- ASP.NET MVC 的URL路由介绍
- ASP.NET 设置DropDownList的当前选项
- spring AspectJ的Execution表达式
- 理解SVG坐标系和变换:视窗,viewBox和preserveAspectRatio
- ASP.NET MVC 4.0 中使用NPOI 2.2.0 按模板生成Excel报表
- ASP.NET 企业组织机构代码验证
- asp.net后台获取路径的各种方法归纳
- 策略模式,ASP.NET实现