ASP.NET MVC Jquery提交Json数据

1、前台通过Jquery提交Json数据

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<script type="text/javascript">
    $(function () {
        var queryJson = "{" +
            "Id:‘" + $("#hidId").val() + "‘," +
            "Name:‘" + $("#txtName").val() + "‘," +
            "Status:‘" + $("#selStatus").val()+ "‘," +
            "}";
        $.ajax({
            url: "/Home/GetAll",
            type: ‘post‘,
            data: { "queryJson": queryJson },
            dataType: "json",
            traditional: true,
            success: function (data) {
                alert("数据查询成功!");
            },
            error: function (message) {
                alert("请求查询数据失败!");
            }
        });
    });
</script>

2、ASP.NET MVC 后台接收数据

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
namespace Demo.Web.MVC.Controllers
{
    public class HomeController : Controller
    {
        /// <summary>
        /// 获取全部信息
        /// </summary>
        /// <returns>返回Json数据</returns>
        public JsonResult GetAll(string queryJson)
        {
            var serializer = new JavaScriptSerializer();
            var queryModel = serializer.Deserialize<QueryModel>(queryJson);
 
            return Json(queryModel);
        }
    }
}
 
public class QueryModel
{
    public Guid Id { get; set; }
 
    public string Name { get; set; }
 
    public string Status { get; set; }
}

  

ASP.NET MVC Jquery提交Json数据,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。