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

[Solved] Having a problem binding to complex objects using custom binding

0 Answers 71 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.
bogus
Top achievements
Rank 1
bogus asked on 29 Oct 2010, 09:09 AM
This is my view:

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

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Index
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>Items</h2>
     <%= Html.Telerik().Grid<Template.Data.Item>()
        .Name("ItemsGrid")
        .DataBinding(binding => binding.Ajax().Select("GetGridSource", "Articole"))
        .Columns(columns=>
            {
                columns.Bound(l => l.Id);
                columns.Bound(l => l.Name);
            })
        .Selectable()
        .Scrollable(x=>x.Enabled(true))
        .EnableCustomBinding(true)
        .Pageable(paging => paging.Total((int)ViewData["ItemsCount"]))
    %>

</asp:Content>

This is the controller , that works fine
 public class ArticoleController : Controller
    {
        public ActionResult Index()
        {
            ViewData["ItemsCount"] = 1;
            return View();
        }

        [GridAction(EnableCustomBinding = true)]
        public ActionResult GetGridSource(GridCommand command)
        {
            IEnumerable<Item> data = new List<Item>
            {
                new Item{ Id=1,Name="name"}
            };
            return View(new GridModel(data)
            {
                Total = 1
            });
        }
    }

This is the controller that doesn't work:
public class ArticoleController : Controller
    {
        public ActionResult Index()
        {
            ViewData["ItemsCount"] = 1;
            return View();
        }

        [GridAction(EnableCustomBinding = true)]
        public ActionResult GetGridSource(GridCommand command)
        {
            IEnumerable<Item> data = new List<Item>
            {
                new Item{ Id=1,Name="name", Location=new Location{Name="location name"}}
            };
            return View(new GridModel(data)
            {
                Total = 1
            });
        }
    }
In this case i get "The requested URL returned 500".
Tags
Grid
Asked by
bogus
Top achievements
Rank 1
Share this question
or