0

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);
        columns.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"])


           %>
      <%}%>
2
  • 2
    It is giving error. OK, does this error come with an error message or something? Commented May 27, 2011 at 10:24
  • linq to entities doesnot recognizes the methos system.string.tostring() Commented May 27, 2011 at 10:28

1 Answer 1

1

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");
Sign up to request clarification or add additional context in comments.

1 Comment

By all means. Telerik grid comes with functionality of CRUD. for more info visit demos.telerik.com/aspnet-mvc/grid?theme=vista

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.