jqGrid is experiencing difficulties retrieving data

Hey there, I have a simple action result that returns a JsonResult. Here is the method:

[HttpPost] 
    public  JsonResult AllEmployees() 
    { 
        EmployeeService employeeService = new EmployeeService(); 
        List<EmployeeViewModel> employeesViewMod = employeeService.allEmployee(); 
        var AllEmpObjects= JsonConvert.SerializeObject(employeesViewMod); 
        return Json(AllEmpObjects); 
    }

We can debug and see the data on AllEmpObjects which is coming from the database.

"[{\"FirstName\":\"shuvo\",\"LastName\":\"ahmed\",\"Address1\":\"110, uttra\",\"Address2\":\"mymansing\",\"HomePhone\":1234,\"MobileNo\":2345,\"Email\":\"[email protected]\",\"Dob\":\"10/01/1977\",\"StartDate\":\"2013-10-01T00:00:00\",\"InitialSalary\":0,\"AccHolderName\":null,\"BankName\":\"brac\",\"Brunch\":\"uttra\",\"AccountNo\":1234567890,\"PositionDDLId\":0,\"MarriageStatDDLId\":0,\"PositionIdString\":\"Md\",\"MarriageIdString\":\"Married\"}]

Here is my JavaScript file that is responsible for displaying data using jqGrid:

function allEmployeeFunc() {
  $("#list").jqGrid({

          url: "/Employee/AllEmployees",
          datatype: "json",
          mtype: "POST",
        colNames: ["First name", "Last Name", "phone", "Mobile", "Email", "status"],

        colModel: [
        { name: "FirstName", width: 55 },
        { name: "LastName", width: 90 }, 
        { name: "HomePhone", width: 80, align: "right" }, 
        { name: "MobileNo", width: 80, align: "right" }, 
        { name: "Email", width: 80, align: "right" }, 
        { name: "MarriageIdString", width: 150, sortable: false } 
    ], 
        pager: "#pager", 
        rowNum: 10, 
        rowList: [10, 20, 30], 
        sortname: "invid", 
        sortorder: "desc", 
        viewrecords: true, 
        gridview: true, 
        autoencode: true, 
        caption: "Detail of all EMPLOYEE",
}); 

}

Unfortunately, there is no data appearing in the output, only the grid displays empty inside. Can anyone please help?

Answer №1

To improve your code, it is advised to delete the line

var AllEmpObjects= JsonConvert.SerializeObject(employeesViewMod);

and update return Json(AllEmpObjects); to

return Json(employeesViewMod);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to remove text from a div when the div width is reduced to 0?

Upon loading the page, my menu is initially set to a width of 0px. When an icon is clicked, a jQuery script smoothly animates the menu's width to fill the entire viewport, displaying all menu items (links) perfectly. The issue I'm facing is that ...

Form with several file selection points

I am working on an application that features a dynamic form capable of uploading files to different individuals simultaneously. Each person is assigned a unique input file and has the option to add up to 2 additional dynamic inputs. <div id="InputsWra ...

What is the best way to convert intricate objects into strings and store them in JavaScript?

Is there a way to persist complex object trees in JavaScript, maintaining both the values and function bindings? When using JSON.stringify and JSON.parse, only the values are stored without information on the type of object being persisted. This causes i ...

Creating scrollable Material tabs

In my application, I am utilizing Material tabs (using mat-tab elements inside a mat-tab-group). When there are too many tabs to be displayed at once, two navigation buttons appear to allow access to the other tabs: https://i.sstatic.net/i7Vhh.png I am l ...

Managing JavaScript Code within the <Head> Tag Following ASP.Net Postback

I've encountered an issue with maintaining my code on postback. Despite having jQuery code in the Head section that functions properly initially, it stops working when a postback occurs! Is there a way to address this problem? Does the head section n ...

The Firefox dropdown menu constantly reverts back to the default option because of JavaScript running in AngularJS

I am currently developing an AngularJS app and encountering issues with select dropdown menus specifically in Firefox. Whenever I click on a select menu and hover over the options, it automatically resets the selected option back to the default/first opti ...

Looking to optimize the JavaScript code for improved performance speed

Is there a more efficient way to avoid writing the same lines of code repeatedly without compromising performance? I've attempted using a for loop to categorize fields as 'mandatory' or 'optional', but it still requires duplicating ...

Retaining ListBox choices in session after a postback event

I have successfully implemented code to store and reselect one selection in a listbox using sessions. However, I am now looking to enhance this functionality to allow for storing and reselecting multiple selections made by the user. Session["SelectedListI ...

Retrieve all references to child elements in React

I am working on a component that renders dynamic children, and I need to assign a unique ref to each child (e.g. ref={'childID' + index}) After the children have been loaded, I am looking for a way to loop through them and access their refs. Is ...

Strategies for Dealing with 'No Search Results' in Your Search Functionality

I am currently facing an issue with displaying "No Results Found" when a user utilizes my search feature. The current problem is that "No Results Found" appears immediately on the screen and then disappears while a search query is being processed, only to ...

Searching for an element using Python's Selenium and JavaScript

on this page I am trying to click on the "Choose file" button but I keep getting the error message: javascript error: argument is not defined var1 = sys.argv[1] path = os.path.abspath(var1) driver.get("https://www.virustotal.com/gui/home/upload& ...

Retrieve information through an AJAX or JavaScript request and use it to fill the selected plugin's multiple selection feature

I have searched everywhere for a solution to this problem, but I haven't been able to find any helpful resources. I apologize in advance if this question has been asked before. What I need to do is to display the data from a JSON object that is fetch ...

Using jQuery to alter the class of div elements in a specific sequence

Currently, I am working on a blog layout using Bootstrap and have encountered an issue. The specific layout requirement is to have the first two divs as col-md-3 (NORMAL), followed by the next 2 divs as col-md-6 (WIDE), then repeating this pattern for the ...

Keep things in line with async functions in Node JS

Hello, I am just starting out with NodeJs and I have a question. I am trying to push elements into an array called files based on the order of the urls provided, but it seems like I'm getting a random order instead. Below is the code I've been wo ...

Using IronPython may prevent accessing a class within another class programmed in C#

In my current project, I am utilizing a .NET library that is written in C#. As part of this, I am running a procedure in IronPython to call a method that creates an object. Here is an example of the code: foo = bar.ProcessAndCreateFoo() # bar is a Bar obj ...

VUE 3 inexplicably failing to display the custom component's template, console remains error-free

I am utilizing flask, html, js for building a web application. I am currently facing an issue where the template defined in the component <add-movie> within movies.js is not being rendered into add_movies.html. The add_movies.html extends base_admin ...

Retrieving data from a string separated by semicolons

Trying to parse a string to extract the AccountName value: var myString = "DefaultEndpointsProtocol=https;AccountName=myAccountName;AccountKey=myAccountKey;EndpointSuffix=whatever.com" My goal is to retrieve "myAccountName" from the string. Is u ...

Identifying page dimensions and implementing CSS adjustments when the width decreases to less than 500 pixels

I'm working on a website and I need to create a script that can detect when the page width is greater than 500px or less than 500px so I can adjust the layout accordingly. At the bottom of the page, there are some links arranged like a footer. When th ...

The ASP.NET update panel requires a double-click to initiate the update

Searching online for solutions has been frustrating, as many have proven ineffective. On my webpage, there are two buttons - a "like" and a "dislike" button. Whenever I click on a button, the update panel fails to refresh initially, although the like data ...

Improving Efficiency with Nested Loop Restructuring

Directions If you have an array of integers, the task is to find the indices of two numbers that add up to a specific target. There will be exactly one solution for each input, and you cannot use the same element twice. For Example Given nums = [2, 7, ...