1

i am facing an issue with mvc telerik grid there is my view :

@(Html.Telerik().Grid(Model.EmployeeList)
.Name("EmployeeGrid")
.Columns(colums =>
    {
        colums.Bound(e => e.First_Name);
        colums.Bound(e => e.Last_Name);
        colums.Bound(e => e.Hire_Date);
        colums.Bound(e => e.Home_Phone);
    })
    .DataBinding(dataBinding => dataBinding.Ajax().Select("_AjaxBinding", "Home"))
    .Groupable()
    .Sortable()
    .Pageable(paging=>paging.PageSize(10))
    .Filterable()
    )

and there is my controller code

[AcceptVerbs(HttpVerbs.Post)]
    [GridAction]
    public ActionResult _AjaxBinding(GridCommand command)
    {
        using (var contax=new NorthwindEntities()){
            int pagesize=command.PageSize;
            int page=command.Page;

            var EmployeeList = (from items in contax.Employees
                                select new
                                {
                                    items.First_Name,
                                    items.Last_Name,
                                    items.Hire_Date,
                                    items.Home_Phone
                                });
            return View(new GridModel
            {
                Data = EmployeeList
            });
        }
    }

on load the data is loaded correctly from database but internal server error 500 occur when i click on paging or sort data.

thanks in advance.

6
  • you can see error detail in browser console.or post the error message here so that we can help you out. Commented Dec 20, 2012 at 7:03
  • Error! the requested URL returned 500 - Internal Server Error Commented Dec 20, 2012 at 8:00
  • have you checked developer tool in response tab?there would be incoming response including detailed server error (asp.net server error) not the browser one. Commented Dec 20, 2012 at 8:05
  • on console there is only one error "the requested URL returned 500 - Internal Server Error" Commented Dec 20, 2012 at 8:39
  • what browser you are using? Commented Dec 20, 2012 at 8:40

1 Answer 1

4

you are using a Linq query inside a disposable scope.but the query execution is deferred until using it (when you have left using {} scope). and you'r context is disposed! solution :

add .ToList at the end of query :

var EmployeeList = (from items in contax.Employees
                                select new
                                {
                                    items.First_Name,
                                    items.Last_Name,
                                    items.Hire_Date,
                                    items.Home_Phone
                                }).ToList();
Sign up to request clarification or add additional context in comments.

Comments

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.