You must Sign In to post a response.
  • Category: ASP.Net MVC

    Ajax call in jquery for web api

    I have developed a web application in ASP.NET MVC 2015. I have a table tblEmployee_Mast i.e. MS SQL Server. I have used entity framework for this web application.Database is developed first and I have developed models for these tables using entity framework. I want to load the employee name as per their designation.

    I have added a new controller for web api i.e. ApiController. The method in controller is as follows -
    public ActionResult Get(string id)
    {
    tblEmployee_Mast objEmp = new tblEmployee_Mast();

    return new JsonResult()
    {
    Data = objEmp ,
    JsonRequestBehavior=JsonRequestBehavior.AllowGet
    };
    }

    The jquery function is as follows -
    function FillEmp()
    {
    var strDesig = $('#ddlDesig').val();
    $.ajax({
    url: '/Api/Values/' + strDesig,type: "GET", dataType: "JSON",data:{ddlDesig:strDesig}, success: function (Emps)
    {
    $("#ddlEmp").html("");
    $.each(Emps, function (i, emp)
    {
    $("#ddlEmp").append($('<option></option>').val(emp.Emp_Code).html(emp.FName));
    })
    }, error: function (Fail) { alert('Fail');}
    });
    }

    I can not get data in Emps
  • #767509
    Hi,

    Rather than check with the code just simply alert one message in success case, if the alert message trigger then recheck your code.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


Sign In to post your comments