Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9200607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:48:20+00:00 2026-06-17T22:48:20+00:00

I am trying to show a DataTable in HTML table through knockout binding…I dont

  • 0

I am trying to show a DataTable in HTML table through knockout binding…I dont know where i am missing or wrong:

My Controller:

     public JsonResult GetEmployees()
     {
        BAL.Employee dbProvider = new BAL.Employee();

        DataTable dataTable = dbProvider.ShowEmployeeDetails();

        List<Model.Employee> objExerciseList = new List<Model.Employee>();

        foreach (DataRow dataRow in dataTable.Rows)
        {
            Model.Employee objExercise = new Model.Employee();

            objExercise.EmployeeCode = dataRow["EmpCode"].ToString();
            objExercise.EmployeeName = dataRow["EmpName"].ToString();

            objExerciseList.Add(objExercise);
        }

        return Json(objExerciseList, JsonRequestBehavior.AllowGet);
    }

My Model:

public class Employee
{
  private string employeeCode;
  private string employeeName;

  public int ID { get; set; }

  [Required(ErrorMessage="Employee Code is Required")]
  public string EmployeeCode
  {
    get
    {
        return employeeCode;
    }
    set
    {
        employeeCode = value;
    }
  }

  [Required(ErrorMessage = "Employee Name is Required")]
  public string EmployeeName
  {
    get
    {
        return employeeName;
    }
    set
    {
        employeeName = value;
    }
  }
}

This is my ViewModel Code:

@{
ViewBag.Title = "Exercise9";
Layout = "../Shared/Master.cshtml";
}

<html>
<head>
<title>KO</title>
<script src="../../Scripts/jquery-1.6.2.js" type="text/javascript"></script>
<script src="../../Scripts/knockout-2.2.1.js" type="text/javascript"></script>
<script src="../../Scripts/knockout.mapping-latest.js" type="text/javascript"></script>
<script src="../../Scripts/json2.js" type="text/javascript"></script>
</head>
<body>
<form action="" method="get">
<div style="width: 990px; background-color: White; height: 710px;">
    <table id="tbllist" align="center" style="border:5px #fff solid;">
        <tr>
            <td colspan="6">
                <h2>
                    Employee List</h2>
            </td>
        </tr>
        <tr>
            <td colspan="6" style="padding: 0px;">
                <div id="title_p">
                    Listing</div>
            </td>
        </tr>
        <tr>
            <th align="left">
                Employee Code
            </th>
            <th align="left">
                Employee Name
            </th>
        </tr>
        <tbody data-bind="foreach: Employees">
            <tr style="border-bottom: 1px solid #000000;">
                <td>
                    <span data-bind="text: EmployeeCode"></span>
                </td>
                <td>
                    <span data-bind="text: EmployeeName"></span>
                </td>
            </tr>
        </tbody>
    </table>
</div>
</form>
<script type="text/javascript">
    var EmpViewModel = function () {
    //Make the self as 'this' reference
    var self = this;
        //Declare observable which will be bind with UI 
        self.EmployeeCode= ko.observable("0");
        self.EmployeeName= ko.observable("");

    //The Object which stored data entered in the observables
    var EmpData = {
        EmpCode:self.EmployeeCode,
        EmpName: self.EmployeeName
        };

    //Declare an ObservableArray for Storing the JSON Response
    self.Employees = ko.observableArray([]);

    GetEmployees(); //Call the Function which gets all records using ajax call

    //Function to Read All Employees
    function GetEmployees() {
        //Ajax Call Get All Employee Records
        $.ajax({
                    type: "GET",
                    url: "/Exercise/GetEmployees/",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                    self.Employees(data); //Put the response in ObservableArray
                    },
                    error: function (error) {
                    alert(error.status + "<--and--> " + error.statusText);
                    }
               });
        //Ends Here
    }
};

ko.applyBindings(new EmpViewModel());
</script>

Please help me…THANKS IN ADVANCE….!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:48:21+00:00Added an answer on June 17, 2026 at 10:48 pm

    Give it a try to convert from Json to observable JavaScript model as follow :

    $.ajax({
                        type: "GET",
                        url: "/Exercise/GetEmployees/",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (data) {
                             ko.mapping.fromJS(data, {}, self.Employees);
                        },
                        error: function (error) {
                        alert(error.status + "<--and--> " + error.statusText);
                        }
                   });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to perform a LINQ query on a DataTable and show the
I'm trying to show a list of links (in index.html) to text files in
I'm trying to filter out rows of an HTML table based on user input
I've been trying to make a datatable..but the data still does not show although
I'm trying to make a dataTable expand on a click to show more information.
I need to pass an entire html table content and trying to pass it
Hi I am trying to load table from MySQL database and show contents of
I'm trying to display html text received from the server in a datatable row.
Trying to show a label only when a certain item in a combo is
I'm trying to show/hide( or simply put - filter ) my markers( of houses

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.