This question is locked. New answers and comments are not allowed.
Hi
I get an error when using RadGrid with Ajax binding and EF 4. According to this link http://www.telerik.com/help/aspnet-mvc/telerik-ui-components-grid-troubleshooting.html#ServerError I need to use ViewModels instead of the normal entities when returning the GridModel since the RadGrid doesn't understand EF assiciations.
I.e. this doesn't work:
I already use a ViewModel for editing my Person entities which looks like this:
My edit action calls the view like this:
This work jus fine. However, I seem to be completely unable to wrap my brain around how to do this for a collection in the Ajax select action.
What would a "GetPeople_As_ViewModel_Collection()" look like?
Re
Dennis
I get an error when using RadGrid with Ajax binding and EF 4. According to this link http://www.telerik.com/help/aspnet-mvc/telerik-ui-components-grid-troubleshooting.html#ServerError I need to use ViewModels instead of the normal entities when returning the GridModel since the RadGrid doesn't understand EF assiciations.
I.e. this doesn't work:
public ActionResult _AjaxBinding() { return View(new GridModel(repository.GetPeople())); }I already use a ViewModel for editing my Person entities which looks like this:
public class PersonFormViewModel
{ // Properties public Person Person { get; set; } public List<Status> Statuses { get; set; } public List<City> Cities { get; set; } public List<Country> Countries { get; set; } // Constructor public PersonFormViewModel(Person person) { Person = person; Statuses = PickLists.GetStatuses().ToList(); Cities = PickLists.GetCities().ToList(); Countries = PickLists.GetCountries().ToList(); } }My edit action calls the view like this:
public ActionResult Edit(int id) { Person person = repository.GetPerson(id); var viewModel = new PersonFormViewModel(person); return View(viewModel); } This work jus fine. However, I seem to be completely unable to wrap my brain around how to do this for a collection in the Ajax select action.
[GridAction] public ActionResult _AjaxBinding() { return View(new GridModel("GetPeople_As_ViewModel_Collection()")); }What would a "GetPeople_As_ViewModel_Collection()" look like?
Re
Dennis