Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Behind Code

C#
public class Employee
        {



            public string Subject { get; set; }


            public string SrvcRef { get; set; }
        }
        

     [WebMethod]

    public static List<employee> GetEmployee(string ID)
    {
        

          
           
            SqlCommand cmd = new SqlCommand("....");   
        
            GetData.con.Open();
        List<employee> employees = new List<employee>();

        SqlDataReader dr = cmd.ExecuteReader();
         
         
        while (dr.Read())
        {
            var employee = new Employee
            {
                Subject = dr["Subject"].ToString(),
                SrvcRef = dr["SrvcRef"].ToString()

            };
            employees.Add(employee);
        }  
        //Close Connection
        dr.Close();
        GetData.con.Close();
        return employees;
       

        }

J query

JavaScript
$(document).on("click", "#LoadLocalDialog1", function () {

                    var ID = $("#<%=grdExiRequest.ClientID %> tr").find("td:eq(0)").html();



                    PageMethods.GetEmployee(ID, onSucess);




                    function onSucess(result) {

                        var speed = $(result).data("Subject");


                    }

                    $("#LocalDialogModal").dialog("open");


                });



I need to get the filed data 'Subject" in jquery. Please help
Posted
Updated 26-May-15 1:37am
v2

1 solution

Change your return type from list to JsonResult :

C#
public JsonResult GetEmployee(string ID)
    {
// retrieve your list here
        return Json(list, JsonRequestBehavior.AllowGet);
    }


You'll get JSON object that jquery can read directly.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900