This is a migrated thread and some comments may be shown as answers.

[Solved] Using Linq to sql in an Telerik MVC Project

1 Answer 97 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
psiegers45
Top achievements
Rank 1
psiegers45 asked on 06 Oct 2011, 04:46 PM
Hi all, we have a problem working with the Grid and Linq to sql in a project that was started using the Telerik MVC 3 Web Application template. The weird thing is that using a project that was created using the built-in template ASP.NET Web Application we can use Linq to sql without problem. But, once we try to use Linq to sql in the Telerik template it does not work. We would expect that both template would support Linq to sql without problem (especially the Telerik one), and we think that we're missing some details on the Model side of the application, however Telerik online demos do not help very much (there's no Model code shown).
So, the main Q is, has anyone bumped into this, and what should we do to sync both generated template code (scripts, content, web.config) to make it work?
Thanks a lot in advance for any help you can offer!

1 Answer, 1 is accepted

Sort by
0
psiegers45
Top achievements
Rank 1
answered on 06 Oct 2011, 05:52 PM
Hi, I'm getting closer to getting it to work.
Actually I'm now able to show up the grid in the Telerik MVC 3 Web Application project.
However, it does NOT show any records yet.
I'll post some code snippets to make clear where I'm standing right now.

Using the demo project I managed to complete following steps:

1. I was able to add Linq to Sql classes, that option did not show before for one or another reason.
2. I added two tables of the Northwind DB, Order and Customer.
3. I added the class OrderDto.cs to the Models.
4. I added the folowing method to the HomeController:

 

 

private static IEnumerable<OrderDto> GetOrderDto()

 

{

 

 

dbIDTDataContext dbidt = new dbIDTDataContext();

 

 

 

DataLoadOptions loadOptions = new DataLoadOptions();

 

loadOptions.LoadWith<

 

Order>(o => o.Customer);

 

dbidt.LoadOptions = loadOptions;

 

 

return dbidt.Orders.Select(order => new OrderDto

 

{

ContactName = order.Customer.ContactName,

OrderDate = order.OrderDate,

OrderID = order.OrderID,

ShipAddress = order.ShipAddress

});

}


5. I changed the page declaration of my view like this

<%

 

@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"

 

 

 

Inherits="System.Web.Mvc.ViewPage<IEnumerable<MvcIDT.Models.OrderDto>>" %>

 


6.  Finally, I added the grid code:

<%

 

= Html.Telerik().Grid(Model)

 

.Name(

 

"Grid")

 

.Columns(columns =>

{

columns.Bound(o => o.OrderID).Width(100);

columns.Bound(o => o.ContactName).Width(200);

columns.Bound(o => o.ShipAddress);

columns.Bound(o => o.OrderDate).Format(

 

"{0:MM/dd/yyyy}").Width(120);

 

})

.DataBinding(dataBinding =>

{

dataBinding.Server().Select(

 

"FirstLook", "Home", new { ajax = ViewData["ajax"] });

 

dataBinding.Ajax().Select(

 

"_FirstLook", "Grid").Enabled(true);

 

})

.Scrollable(scrolling => scrolling.Enabled(

 

true))

 

.Sortable(sorting => sorting.Enabled(

 

true))

 

.Pageable(paging => paging.Enabled(

 

true))

 

.Filterable(filtering => filtering.Enabled(

 

true))

 

.Groupable(grouping => grouping.Enabled(

 

true))

 

.Footer(

 

true)

 

%>


Can anyone tell me why the data does not show up?
TIA, Pieter
Tags
Grid
Asked by
psiegers45
Top achievements
Rank 1
Answers by
psiegers45
Top achievements
Rank 1
Share this question
or