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

Problem binding to ViewData

1 Answer 848 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 2
Dan asked on 21 May 2014, 05:26 PM
I have a Razor page with a Kendo grid, trying to bind to ViewData.  The page is showing a syntax problem on the @(Html.Kendo().Grid line as shown below.  I can't figure out why the page won't render.  This is just like the example at
http://docs.telerik.com/kendo-ui/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/server-binding

Dan
Controller code:
public ActionResult PatientMedInfo(long id)
        {
            IContextManager contextManager = ManagerConfig.GetManagerForUser(Session[SessionItems.AuthenticatedUser] as DHS.Entities.IDHSPrincipal);
            IWorkContext workContext = contextManager.Begin();
 
            DHS.Entities.Patient patient = workContext.GetPatientManager().GetById(id);
            ICollection<DHS.Entities.PatientCatheter> catheterlog = workContext.GetPatientManager().FindCatheters(patient);
 
            IEnumerable<Catheter> cats = catheterlog.Select(cat => new Catheter
            {
                Id = cat.Id,
                CatheterType = cat.CatheterType,
                EffectiveDate = cat.EffectiveDate,
                DiscontinuedOn = cat.DiscontinuedOn,
                Manufacturer = cat.Manufacturer,
                Clinician = cat.Clinician
            }).OrderBy(x => x.EffectiveDate);
 
            ViewData["catheters"] = cats;
 
            return View(Views.EmployeeMedInfo, CPR.WebPortal.Models.PatientMedInfo.Populate(workContext, workContext.GetPatientManager().GetById(id)));
        }
 
Razor page:
@model PatientMedInfo
 
@(Html.Kendo().Grid((IEnumerable<Catheter>)ViewData["catheters"])
            .Name("CatheterGrid")
            .Columns(columns =>
            {
                columns.Bound(e => e.CatheterType.Name).Title("Type");
                columns.Bound(e => e.EffectiveDate).Title("Placed On").Format("{0:d}");
                columns.Bound(e => e.DiscontinuedOn).Title("Discontinued On");
                columns.Bound(e => e.Manufacturer.Name).Title("Manufacturer");
                columns.Bound(e => e.ClinicianDisplayName).Title("Clinician");
                columns.Bound(e => e.Id).Hidden();
                columns.Bound(e => e.Id).ClientTemplate(
                    "<a href='" + Url.Action("EditCatheter", Controllers.Patient) + "/#= Id #'" + "class='btn btn-sm'>Edit</a>"
                    ).Width(80).Title("");
            })
            .Pageable(pageable => pageable
                .PageSizes(true).PageSizes(new int[] { 20, 50, 100 })
                .ButtonCount(5))
            .Sortable()
            .Filterable()
            .Scrollable()
            .ClientDetailTemplateId("template")
            .ToolBar(toolbar =>
            {
                toolbar.Template(@<text>
                    <div style="float:right">
                        <a href='@Url.Action("EditCatheter", Controllers.Patient)/0' class='btn btn-sm'>New</a>
                    </div>
                </text>);
            })

1 Answer, 1 is accepted

Sort by
0
Dan
Top achievements
Rank 2
answered on 22 May 2014, 07:46 PM
Found it.  I was missing a parentheses.  Getcha every time...

Dan
Tags
Grid
Asked by
Dan
Top achievements
Rank 2
Answers by
Dan
Top achievements
Rank 2
Share this question
or