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 6374817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:32:08+00:00 2026-05-25T01:32:08+00:00

I’m trying to implement a jqGrid with MVC. The Model is: public class InvoiceHeader

  • 0

I’m trying to implement a jqGrid with MVC.

The Model is:

public class InvoiceHeader
    {
        public int id { get; set; }
        public DateTime invdate { get; set; }
        public int clientid { get; set; }
        public decimal amount { get; set; }
        [Display(Name = "Invoice Number:")]
        public int tax { get; set; }
        public decimal total { get; set; }
        [Required(ErrorMessage = "Note is a required field.")]
        [Display(Name = "Note:")]
        public string note { get; set; }
        public int PaymentTypeId { get; set; }
        public string CreatedByUsername { get; set; }

        public virtual PaymentType PaymentType { get; set; }
    }

My View is:

    @model JQGRID.Models.InvoiceHeader
@{
    ViewBag.Title = "Home Page";
}
@*<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />*@ <title>My First
    Grid</title>@*<link rel="stylesheet" type="text/css" media="screen" href="css/ui-lightness/jquery-ui-1.7.1.custom.css" />*@
<link rel="stylesheet" type="text/css" media="screen" href="../../Scripts/css/ui.jqgrid.css" />
<link rel="stylesheet" type="text/css" media="screen" href="../../Scripts/css/ui.multiselect.css" />
@*<link rel="stylesheet" type="text/css" media="screen" href="../../Content/themes/ui-lightness/jquery-ui-1.8.14.custom.css" />*@
<style>
    html, body
    {
        margin: 0;
        padding: 0;
        font-size: 75%;
    }
</style>

<script src="../../Scripts/js/jquery-1.5.2.min.js" type="text/javascript"></script>

<script src="../../Scripts/js/i18n/grid.locale-en.js" type="text/javascript"></script>

<script src="../../Scripts/js/jquery.jqGrid.min.js" type="text/javascript"></script>

@*<script src="../../Scripts/src/grid.inlinedit.js" type="text/javascript"></script>*@

<script type="text/javascript">

    jQuery(document).ready(function () {
        jQuery("#list").jqGrid({
            url: '/Home/DynamicGridData/',
            datatype: 'json',
            mtype: 'POST',
            colNames: ['id', 'note', 'tax', 'PaymentType', 'CreatedByUsername', 'Actions'],
            colModel: [
                { name: 'id', index: 'id', hidden: true, editable: false },
              { name: 'note', index: 'note', width: 40,align:'center', editable: true, editrules: { required : true } },
              { name: 'tax', index: 'tax', width: 400, align: 'center', editable: true, editrules: { required : true } },
              { name: 'PaymentTypeId', index: 'PaymentTypeId', width: 400, align: 'center', editable: true, edittype:"select", 
                editoptions: { dataUrl: '/Home/PaymentTypes/' }},
              { name: 'CreatedByUsername', index: 'CreatedByUsername', hidden: true, editable: false },
              { name: 'act',index:'act',width:55,align:'center',sortable:false,formatter:'actions',
                     formatoptions:{
                         keys: true, // we want use [Enter] key to save the row and [Esc] to cancel editing.
                         beforeSubmit:function(postdata, formid) {
                         alert("Hi");
                             jQuery("#ValidationSummary").show('slow');
                         },

                         },}
              ],
            pager: jQuery('#pager'),
            rowNum: 10,
            rowList: [5, 10, 20, 50],
            sortname: 'Id',
            sortorder: "desc",
            viewrecords: true,
            imgpath: '',
            caption: 'My first grid',
            editurl: '/Home/Save/'
        });
        jQuery("#list").navGrid('#pager', { edit: false, search: false, add: true });

    }); 
</script>

@using (Html.BeginForm()) {
@Html.ValidationSummary()
<table id="list">
</table>
<div id="pager">
</div>}

As you can see on Save the following method in the controller is called:

public void Save(InvoiceHeader invoiceHeader)
        {
            if (ModelState.IsValid) {
                ...
                try {
                    context.SaveChanges();
                }
                catch (Exception ex) {

                }
            }
        }

What I don’t understand is why when you enter this method and check invoiceHeader properties the id property is populated but the CreatedByUsername property is not populated.

I really need this property populated to save.

Could someone please explain to me why this is and how I can get CreatedByUsername populated?

  • 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-05-25T01:32:09+00:00Added an answer on May 25, 2026 at 1:32 am

    Did you check the values of the Id object in your Save action? They should be the row id in the grid, not the actual Id of the object you’re editing.

    To prevent this, you should try adding columns for the Id and the CreatedByUserName columns and make them invisible. Also, add a key:true value to your Id column. That way, while editing, the values will get populated from those columns.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put

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.