Data is not showing up in View

I'm trying to show the data grid in default column from my existing data table in in code first approach but no data is showing in the view.

My Model (tbl_mdl.cs) class is as below:

public partial class tbl_mdl
    {
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
        public tbl_mdl()
        {
            tbl_submission = new HashSet<tbl_submission>();
        }

        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        public int drawing_id { get; set; }

        [StringLength(255)]
        public string drawing_number { get; set; }

        public int? last_rev { get; set; }

        [StringLength(255)]
        public string last_appcat { get; set; }

        [StringLength(255)]
        public string drawing_desc { get; set; }

        public int? ss_id { get; set; }

        public int? subcat_id { get; set; }

        public DateTime? planned_submission { get; set; }

        public DateTime? planned_approval { get; set; }

        public DateTime? actual_submission { get; set; }

        public DateTime? actual_approval { get; set; }

        public virtual tbl_listss tbl_listss { get; set; }

        public virtual tbl_subcat tbl_subcat { get; set; }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        public virtual ICollection<tbl_submission> tbl_submission { get; set; }
    }

My Controller (DrawingController.cs) class is as below:

// GET: Drawing
        public ActionResult Index()
        {
            return View();
        }

        // GET: Drawing
        public ActionResult GetAllDrawings()
        {
            ViewBag.dataSource = db.tbl_mdl.Include(t => t.tbl_listss).Include(t => t.tbl_subcat).ToList();
            return View();
        }

My Index.cshtml is as follows:

@model IEnumerable<FinalTestWithSyncfusion.Models.tbl_mdl>

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Index</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<div id="ControlRegion">
    @Html.EJS().Grid("FlatGrid").DataSource((IEnumerable<object>)ViewBag.dataSource).AllowPaging(true).Render()
</div>

But no data is showing up in the view as detailed hereunder:


Kindly help.

Attachment: Upload_d3a057ab.zip

3 Replies 1 reply marked as answer

SK Sujith Kumar Rajkumar Syncfusion Team February 22, 2021 11:39 AM UTC

Hi Santanu, 
 
Greetings from Syncfusion support. 
 
We checked your reported problem but unfortunately were unable to reproduce it from our end as the Grid data was properly bound and displayed in the Grid. You can check the below sample for your reference, 
 
 
Note: We have used a local MDF file in the above sample to assign and process the data. So before running the sample, please make sure the connection for this file is established in the server explorer and the correct connection string is provided OrderDbContext.cs file in the application. 
 
We would like to let you know that the reported problem usually occurs if the data is not properly set to the Grid. In the shared code snippet we could see that you have defined the Grid in the Index.cshtml file but you have provided the data source using viewbag data in the GetAllDrawings action method instead of the Index method. So please ensure from your end if you have provided the data in the proper controller action method based on the rendered Grid. 
 
If problem still persists then please share us the following information to validate further on this, 
 
  • Are any console errors thrown?
  • Syncfusion package version used.
  • If possible share us a simple to replicate the problem or try reproducing it in the above provided sample.
 
Regards, 
Sujith R 



SA Santanu February 25, 2021 03:30 PM UTC

Thank you very much for your help. But I managed to do the same with the following code snippet in Controller and data is rendering as required.:



Marked as answer

SK Sujith Kumar Rajkumar Syncfusion Team February 26, 2021 05:51 AM UTC

Hi Santanu, 
 
You’re welcome. We are glad to hear that your query has been resolved. 
 
Please get back to us if you require any further assistance. 
 
Regards, 
Sujith R 


Loader.
Up arrow icon