This is a migrated thread and some comments may be shown as answers.
MVC Ajax Grid Issue
1 Answer 5 Views
This is a migrated thread and some comments may be shown as answers.
Mark A
Top achievements
Rank 2
Mark A asked on 11 Sep 2019, 06:24 PM

I am pretty new to MVC/Telerik and am having an issue populating a grid. I created the standard Telerik MVC5 project with the Grid and menu. I added my model, created a context and updated the controllers and views. When i run the app on the Visual Studio IIS Express instance i have zero issues. However, once i publish it to an IIS 8 test server i receive HTTP 500 errors and an empty grid.Looking at the Fiddler results it appears that the read function on grid is the issue.

 

Grid Controller

public partial class GridController : Controller
{   
        public ActionResult Orders_Read([DataSourceRequest]DataSourceRequest request)
        {         
            using (var ctx = new CWDataContext())
            {
                IQueryable<CWDataModel> carts = ctx.CW_Data;
                DataSourceResult result = carts.ToDataSourceResult(request);
                return Json(result);
            }
        }
}

 

Home Controller

 public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";
            return View();
        }
    }

 

Model

   [Table("CWCartLblFile")]
    public class CWDataModel
    {
        [Key]
        public int Row_ID { get; set; }
        public string COLOR { get; set; }
        public string SKU { get; set;

    }

 

Context

public class CWDataContext : DbContext
    {
        public CWDataContext() : base("defaultString")
        {            
        }
        public DbSet<CWDataModel> CW_Data {get; set;}
}

 

Index View

<div class="row">
    <div class="col-12">
        @(Html.Kendo().Grid<TelerikMvcApp1.Models.CWDataModel>()
            .Name("grid")
            .Columns(columns =>
            {
                columns.Bound(product => product.COLOR).Width(50);
                columns.Bound(product => product.SKU).Width(50);
            })
            .Pageable()
            .Sortable()
            .Scrollable()
            .Filterable()
            .HtmlAttributes(new { style = "height:550px;" })
            .DataSource(dataSource => dataSource
                .Ajax()
                .PageSize(20)
                .Read(read => read.Action("Orders_Read", "Grid"))
            )
        )
    </div>
</div>

 

I am not sure if something in the code is incorrect or i overlooked something on the web server.

 

1 Answer, 1 is accepted

Sort by
0
Mark A
Top achievements
Rank 2
answered on 12 Sep 2019, 12:49 PM
I figured it out. There was an issue with the connection string for the SQL DB. Doh!
Tags
Grid
Asked by
Mark A
Top achievements
Rank 2
Answers by
Mark A
Top achievements
Rank 2
Share this question
or