i have tried the following code and it is giving error
var res = (from results in db.JobSearchAgents
where results.SiteID == 110 && results.UserID == sess
select new Agentlist
{
JobSearchAgentID = results.JobSearchAgentID.ToString(),
EmailAddress = results.EmailAddress,
Keywords = results.Keywords,
Country = results.Country,
zipcode = results.ZipCode,
miles = results.Miles.ToString()
}).AsEnumerable();
ViewData["ajax"] = true;
ViewData["scrolling"] = true;
ViewData["paging"] = true;
ViewData["filtering"] = true;
ViewData["grouping"] = true;
ViewData["sorting"] = true;
ViewData["showFooter"] = true;
//ViewData["searchresults"] = res;
return View(res);
<%using (Html.BeginForm())
{%>
<%=Html.Telerik().Grid(Model).Name("Grid").Columns(columns=>
{
columns.Bound(m=>m.Keywords);
colu开发者_如何学JAVAmns.Bound(m=>m.Country);
}).DataBinding(databinding=>
{
databinding.Server().Select("Agentlist","Grid",new
{
ajax=ViewData["ajax"]
});
databinding.Ajax().Select("Agentlist",
"Grid").Enabled((bool)ViewData["ajax"]);
})
.Scrollable(scrolling => scrolling.Enabled((bool)ViewData["scrolling"]))
.Sortable(sorting => sorting.Enabled((bool)ViewData["sorting"]))
.Pageable(paging => paging.Enabled((bool)ViewData["paging"]))
.Filterable(filtering => filtering.Enabled((bool)ViewData["filtering"]))
.Groupable(grouping => grouping.Enabled((bool)ViewData["grouping"]))
.Footer((bool)ViewData["showFooter"])
%>
<%}%>
The Error is because your query is trying to execute ToString method in db. using AsEnumerable you can tell the query to execute your methods in c#. you can either change your query to
var res = (from results in db.JobSearchAgents
where results.SiteID == 110 && results.UserID == sess
select result).AsEnumerable().Select(result=>new Agentlist
{
JobSearchAgentID = results.JobSearchAgentID.ToString(),
EmailAddress = results.EmailAddress,
Keywords = results.Keywords,
Country = results.Country,
zipcode = results.ZipCode,
miles = results.Miles.ToString()
});
Or you can bind your columns to telerik grid without calling ToString method. Telerik grid does not require the data to be in string format. Moreover, if you want data to be displayed in specific format you can call Format method when binding to the grid
columns.Bound(m=>m.Keywords).Foramt("format string");
精彩评论