在MVC4中通过JSON检索列表数据 [英] Retrieving a list data by JSON in MVC4

查看:59
本文介绍了在MVC4中通过JSON检索列表数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是MVC的初学者。现在我正在尝试从控制器中检索列表数据。获取数据时我没有收到任何错误。但它没有用。



我的代码是,



客户端



I am a beginner in MVC. Now i am trying to retrieve a list data from a controller. I am not getting any error while fetching the data. But its not working.

My code is,

Client Side

function ff_bind(drop_compny, drop_survey) {
        alert("test");
        debugger;
        $.ajax({
            type: "POST",
            url: "../ManageEmployeNumber/ff_bind_dept",
            contentType: "application/json; charset=utf-8",
            data: "{ 'comp_id': " + drop_compny + ",'surv_id':" + drop_survey + " }",            
            //data: { comp_id: drop_compny },
            dataType: "json",
            success: function (data) {
                debugger;
                alert(result)
            },
            error: function (response) {
                debugger;
                alert(response.d);
            }
        });
    }





服务器端





server side

public tblDepartment[] ff_bind_dept(int comp_id, int surv_id)
        {
           
            List<tblDepartment> lis_dept = new List<tblDepartment>();
            lis_dept = db.tblDepartments.Where(s => s.CompID == comp_id).ToList();

            return lis_dept.ToArray();
        }





Class





Class

public partial class tblDepartment
    {
        public decimal DeptID { get; set; }
        public Nullable<decimal> CompID { get; set; }
        public string DeptName { get; set; }
        public Nullable<decimal> NoEmployee { get; set; }
        public Nullable<double> TrgScore { get; set; }

        public virtual tblCompany tblCompany { get; set; }
    }







请帮帮我...



提前感谢..




please help me...

thanks in advance..

推荐答案

.ajax({
type: POST
url: ../ ManageEmployeNumber / ff_bind_dept
contentType: application / json ; charset = utf-8
data: {'comp_id': + drop_compny + ,'surv_id': + drop_survey + }
// data:{comp_id:drop_compny},
dataType: json
成功: function (data){
调试器;
提醒(结果)
},
错误: function (回复){
调试器;
alert(response.d);
}
});
}
.ajax({ type: "POST", url: "../ManageEmployeNumber/ff_bind_dept", contentType: "application/json; charset=utf-8", data: "{ 'comp_id': " + drop_compny + ",'surv_id':" + drop_survey + " }", //data: { comp_id: drop_compny }, dataType: "json", success: function (data) { debugger; alert(result) }, error: function (response) { debugger; alert(response.d); } }); }





服务器端





server side

public tblDepartment[] ff_bind_dept(int comp_id, int surv_id)
        {
           
            List<tblDepartment> lis_dept = new List<tblDepartment>();
            lis_dept = db.tblDepartments.Where(s => s.CompID == comp_id).ToList();

            return lis_dept.ToArray();
        }





Class





Class

public partial class tblDepartment
    {
        public decimal DeptID { get; set; }
        public Nullable<decimal> CompID { get; set; }
        public string DeptName { get; set; }
        public Nullable<decimal> NoEmployee { get; set; }
        public Nullable<double> TrgScore { get; set; }

        public virtual tblCompany tblCompany { get; set; }
    }







请帮帮我...



提前感谢..




please help me...

thanks in advance..


function ff_bind(drop_compny, drop_survey) {
        alert("test");
        debugger;


.ajax({
type: POST
data: {comp_id:' + drop_compny + ',surv_id:' + drop_survey + '}
url: ../ ManageEmployeNumber / ff_bind_dept
contentType: application / json; charset = utf-8
// data:{comp_id:drop_compny},
dataType: json
成功: function (data){
debugger ;
提醒(结果)
},
错误: function (回复){
调试器;
alert(response.d);
}
});
}
.ajax({ type: "POST", data: "{ comp_id: '" + drop_compny + "',surv_id:'" + drop_survey + "' }", url: "../ManageEmployeNumber/ff_bind_dept", contentType: "application/json; charset=utf-8", //data: { comp_id: drop_compny }, dataType: "json", success: function (data) { debugger; alert(result) }, error: function (response) { debugger; alert(response.d); } }); }


这篇关于在MVC4中通过JSON检索列表数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆