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

[Solved] Linq recordset binding

5 Answers 67 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.
caddy
Top achievements
Rank 1
caddy asked on 18 Mar 2010, 05:52 PM
Probably a stupid question and I may not even be using the right terms since I am fairly new to Mvc.  That being the case I have failed to find an answer to my question, so I will put it out here.

In my controler I have the following;

 

 

public ActionResult contact()

 

{

truckTrax.Models.

truckTraxDataContext myTrax = new Models.truckTraxDataContext();
var x = from c in myTrax.contacts

 

join p in myTrax.phones on c.contactID equals p.contactId

 

 

join f in myTrax.phones on c.contactID equals f.contactId

 

 

 

 

join a in myTrax.addresses on c.contactID equals a.contactId

 

 

 

select new

 

{

c.firstName,

c.lastName,

c.middleName,

c.note,

a.address1,

a.address2,

a.City,

a.state,

a.postalCode,

}

;

return View((IQueryable)x);

}
The problem is how do I wire this up to the view?  I have attempted multiple ways and as of yet can find no way to wire this to the view.

At present I have this which obviously is completely wrong but a bit of guidence would be greatly appreciated.

 

<%

 

@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<System.Data.Linq.Table<x>>" %>

 

<%

 

@ Import Namespace="truckTrax" %>

 

 

<%

 

@ Import namespace="truckTrax.helpers" %>

 

<

 

 

asp:Content ID="EmployeeSubMenu" ContentPlaceHolderID="SubMenuHolder" runat="server">

 

<div class="subMenuPage">

 

<ul id="subMenu">

 

<li><%= Html.ActionLink("Employees", "Employees", "officemgt")%></li>

 

<li><%= Html.ActionLink("Drivers", "Drivers", "officemgt")%></li>

 

 

 

<li><%= Html.ActionLink("Accident Report", "accident", "officemgt")%></li>

 

<li><%= Html.ActionLink("Add New Employee", "addEmloyee", "officemgt")%></li>

 

</ul>

 

 

</div>

 

</

 

 

asp:Content>

 

 

 

 

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

 

 

 

 

<h2>Employees</h2>

 

<%

 

= Html.Telerik().Grid(x)

 

.Name(

 

"Grid")

 

.Columns(columns =>

 

 

 /* Column Bindings will go here */

 })

 .Sortable()

.Filterable()%>

 

 

<div id="pager"></div>

 

 

 

</asp:Content>


Thanks for any help that could be provided.

 

 

 

 

5 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 19 Mar 2010, 08:59 AM
Hello caddy,

Please check the Server Binding help topic

Regards,
Georgi Krustev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
caddy
Top achievements
Rank 1
answered on 19 Mar 2010, 05:39 PM
Thanks for the reply, but I must be really dense.

I have added the following to my controller:

ViewData[

 

"contacts"] = x;

 

 

 

return View();

 


the view looks like this (now):

<%

 

= Html.Telerik().Grid<truckTrax.Controllers.officemgtController>("contacts")

 

.Name(

 

"contacts")

 

.BindTo(((

 

IEnumerable<truckTrax.Controllers.officemgtController>)ViewData["contacts"]))

 

.Pageable()

.Sortable()

.Filterable()

%>
 I have tried numerous variations this one does not render any errors  until I run it. Then I get
System.InvalidCastException: Unable to cast object of type 'System.Data.Linq.DataQuery`1[<>f__AnonymousType4`10[System.Int32,System.String,System.String,System.String,System.String,System.String,System.String,System.String,System.String,System.String]]' to type 'System.Collections.Generic.IEnumerable`1[truckTrax.Controllers.officemgtController]'.

Taking out the binding the grid renders however as expected I get no data.  So apparently I am completely clueless or missing something.   Like I have said I have tried many variations of the given examples however, I do not seem to be able to pass a set of data to the view passed on a Linq query.

0
caddy
Top achievements
Rank 1
answered on 22 Mar 2010, 04:26 PM
Ok as an update I get things looking pretty good no code errors until I add the .Render();  in the view.  Then I get a "Cannot implicitly convert type 'void' to 'object'

I can get a list of records no problem I can send them to the view either using

ViewData["contacts"] = myCont;  // this is a list of a class that I build from my Linq to SQL query

or I can send it  as:

return View(myCont);

So I am at the point that I am not sure about the wiring at the top of the view I am using the following which obviously isn't right but I have tried a myriad of different code seqments

<%

 

@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<List<truckTrax.Controllers.Contacts>>" %>

and at the grid definiton:

 

<%

 

= Html.Telerik().Grid<truckTrax.Controllers.Contacts>()

 

 

.Name(

 

"Contacts")

 

 

.Pageable()

.Sortable()

.Filterable()

.Render();

%>


So can anyone actually poiint me to the proper syntax here before I completly lose my mind.

Thanks for any forth comming help

0
Georgi Krustev
Telerik team
answered on 22 Mar 2010, 06:09 PM
Hi caddy,

You need to use either <% %> server tag with .Render() method or <%= %> without Render() method. In ASP.NET <%= %> is equal to Respose.Write(...);

Kind regards,
Georgi Krustev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
caddy
Top achievements
Rank 1
answered on 22 Mar 2010, 06:39 PM
Thanks,

I have been staring so long at the code that I completly missed that typo.
Tags
Grid
Asked by
caddy
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
caddy
Top achievements
Rank 1
Share this question
or