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

  • Home
  • SEARCH
  • 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 9230253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:46:45+00:00 2026-06-18T05:46:45+00:00

I’m trying to create a simple user – role management project using asp.net mvc3

  • 0

I’m trying to create a simple user – role management project using asp.net mvc3 Entity Framework 4 (first model) and use jqgrid to display the data.

but why if I change data relationships between table user and role into many-to-many relation ship,
jqgrid failed to load data.

Below is My Project data:

Project data:

  1. VS 2010
  2. ASP.Net MVC 3
  3. View : Razor
  4. ORM: Linq To Entity
  5. JQGrid Version : jqGrid 3.8

  6. Project Package :

    • EntityFramework” version=”4.1.10715.0
    • jQuery” version=”1.5.1
    • jQuery.UI.Combined” version=”1.8.11
    • jQuery.Validation” version=”1.8.0
    • jQuery.vsdoc” version=”1.5.1″
    • Modernizr” version=”1.7
    • MvcScaffolding” version=”1.0.6
    • T4Scaffolding” version=”1.0.5

Model :


– User

    public partial class User
{

    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)] 
    public int UserId { get; set; }
    public string UserName { get; set; }
    public string LoweredUserName { get; set; }
    public string MobileAlias { get; set; }
    public bool IsAnonymous { get; set; }
    public System.DateTime LastActivityDate { get; set; }

    public virtual ICollection<Role> Roles { get; set; }
}

– Role

    public partial class Role
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)] 
    public int RoleId { get; set; }
    public string RoleName { get; set; }
    public string LoweredRoleName { get; set; }
    public string Description { get; set; }

    public virtual ICollection<User> Users { get; set; }
}


Controler-User :

        public JsonResult GridData(int rows, int page)
    {
        var count = _context.Users.Count();

        var pageData = _context.Users.OrderBy(x => x.UserId).Skip((page - 1) * rows).Take(rows);

        return Json(new {
            page = page,
            records = count,
            rows = pageData,
            total = Math.Ceiling((decimal)count / rows)
        }, JsonRequestBehavior.AllowGet);
    }


View-Index.cshtml :

@model IEnumerable<CustomControler.Models.User>

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<table id="ajaxGrid"></table>
<div id="ajaxGridPager"></div>

<script type="text/javascript">
    jQuery("#ajaxGrid").jqGrid({
        url: '@Url.Action("GridData")',
        datatype: "json",
        mtype: 'GET',
        colNames: ['UserId', 'UserName', 'LoweredUserName', 'MobileAlias', 'IsAnonymous', 'LastActivityDate'],
        colModel: [
            { name: 'UserId', index: 'UserId', editable: true, sortable: false, hidden: true },
            { name: 'UserName', index: 'UserName', editable: true, sortable: false, hidden: false },
            { name: 'LoweredUserName', index: 'LoweredUserName', editable: true, sortable: false, hidden: false },
            { name: 'MobileAlias', index: 'MobileAlias', editable: true, sortable: false, hidden: false },
            { name: 'IsAnonymous', index: 'IsAnonymous', editable: true, sortable: false, hidden: false },
            { name: 'LastActivityDate', index: 'LastActivityDate', editable: true, sortable: false, hidden: false }
        ],**
        rowNum: 5,
        pager: '#ajaxGridPager',
        width: '850',
        height: '15em'
    });
    //jsonReader: { repeatitems: false, id: "UserId" },
    jQuery("#ajaxGrid").jqGrid('navGrid', '#ajaxGridPager',
        { search: false, refresh: false },                     // General options
        { url: '@Url.Action("Edit")', closeAfterEdit: true },  // Edit options
        { url: '@Url.Action("Create")', closeAfterAdd: true }, // Add options
        { url: '@Url.Action("Delete")' }                       // Delete options                           
    );    
</script>


Master page

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=9" />

    <title>@ViewBag.Title</title>

    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.5.2.min.js")" type="text/javascript"></script>

    <!-- To support jqGrid -->
    <link href="@Url.Content("~/Content/themes/base/jquery.ui.all.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/ui.jqgrid.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/i18n/grid.locale-en.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.jqGrid.min.js")" type="text/javascript"></script>



</head>

If i set comment to public virtual ICollection <Role> Roles {get; set;} on my User Model, which means I get rid of role relation ship to the table, data can be
loaded in jqGrid.

  • 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-18T05:46:46+00:00Added an answer on June 18, 2026 at 5:46 am

    Solved/Answered By tpeczek :

    The problem is not with jqGrid, but with JavaScriptSerializer trying to serialize the entire objects tree (and getting lost in it), the easiest way around is to use anonymous object (not perfect as you have to type the properties you want to send, but will do the trick)

    See : forums.asp.net

    Hope This Will Be Helpful to Others

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I'm making a simple page using Google Maps API 3. My first. One marker
I'm using an ASP request returning a XML file containing some latin characters. By
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.