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

Grid - Create - causes <replaceme> is undefined

2 Answers 149 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 03 Oct 2012, 06:39 AM
Hi all, I hope someone can help on this odd problem I have.
I am performing binding against some objects called Instances.
Each Instance has a couple of strings, and another object called a Hosting Environment.
HostingEnvironment has the LocationName as a string.

So I'm using a ClientTemplate to display LocationName, while binding to the HostingEnvironment for that grid column.
I'm also using a PartialView for displaying the list of HostingEnvironment locations names in a dropdown during an edit.
That all works great, I can view and edit records.

The problem happens as soon as I click the "Create" button... it immediately throws an error:
0x800a1391 - JavaScript runtime error: 'HostingEnvironment' is undefined

When I break into the generated code, I can see that all the strings are blank (a good thing) except HostingEnvironment doesn't have a value (yes it's null)... so I guess the PartialView doesn't like that maybe?

I'm not really sure what to do...

Here's my main view.

@model IEnumerable<Core.Domain.Entities.Instance>

@(Html.Kendo().Grid(Model)
    .Name("Instances")
    .Columns(columns =>
    {
        columns.Bound(p => p.InstanceName).Title("Instance Name");
        columns.Bound(p => p.InstanceFullName).Title("Instance Full Name");
        columns.Bound(p => p.HostingEnvironment);//.Title("Hosting Environment").ClientTemplate("#: HostingEnvironment.LocationName #");
        columns.Bound(p => p.SysId);
        columns.Command(command => {command.Edit(); command.Destroy(); });
    })
    .Pageable()
    .Sortable()
    .Scrollable() 
    .Filterable()
    .ToolBar(commands => commands.Create()) 
    .Editable(editable => editable.Mode(GridEditMode.InLine))
    .DataSource(dataSource => dataSource        
        .Ajax()
        .Model(model => model.Id(p => p.SysId))
        // Configure CRUD -->
        .Create(create => create.Action("CreateNew", "Instance"))
        .Read(read => read.Action("Read", "Instance"))
        .Update(update => update.Action("Update", "Instance"))
        .Destroy(destroy => destroy.Action("Destroy", "Instance"))
        // <-- Configure CRUD        
     )
)

2 Answers, 1 is accepted

Sort by
0
Jon
Top achievements
Rank 1
answered on 03 Oct 2012, 07:23 AM
I read a few other posts and tried the DefaultValue method.

The problem now is that I get the error:
'Core.Domain.Entities.Instance.HostingEnvironment' is a 'property' but is used like a 'type'

Code below:

@model IEnumerable<Core.Domain.Entities.Instance>

@(Html.Kendo().Grid(Model)
    .Name("Instances")
    .Columns(columns =>
    {
        columns.Bound(p => p.InstanceName).Title("Instance Name");
        columns.Bound(p => p.InstanceFullName).Title("Instance Full Name");
        columns.Bound(p => p.HostingEnvironment);//.Title("Hosting Environment").ClientTemplate("#: HostingEnvironment.LocationName #");
        columns.Bound(p => p.SysId);
        columns.Command(command => { command.Edit(); command.Destroy(); });
    })
    .Pageable()
    .Sortable()
    .Scrollable()
    .Filterable()
    .ToolBar(commands => commands.Create())
    .Editable(editable => editable.Mode(GridEditMode.InLine))
    .DataSource(dataSource => dataSource
        .Ajax()
        .Model(model =>
            {
                model.Id(p => p.SysId);
                model.Field(he => he.HostingEnvironment).DefaultValue(
                    new
                        Core.Domain.Entities.Instance.HostingEnvironment()
                    );
            })
        // Configure CRUD -->
        .Create(create => create.Action("CreateNew", "Instance"))
        .Read(read => read.Action("Read", "Instance"))
        .Update(update => update.Action("Update", "Instance"))
        .Destroy(destroy => destroy.Action("Destroy", "Instance"))
        // <-- Configure CRUD        
     )
)
0
Jon
Top achievements
Rank 1
answered on 03 Oct 2012, 08:04 AM
ok, I finally figured this out... it was a combination of fixing a namespace issue I had in my code, and then I had the same problem as some other folks with the object not being serializable. I followed the instructions on this thread:
http://www.kendoui.com/forums/mvc/grid/ajax-binding-clienttemplate-issue-with-create-action.aspx
and got the latest internal build (v 2012.2.803.340).

Here is my final code:
@model IEnumerable<Core.Domain.Entities.Instance>

@(Html.Kendo().Grid(Model)
    .Name("Instances")
    .Columns(columns =>
    {
        columns.Bound(p => p.InstanceName).Title("Instance Name");
        columns.Bound(p => p.InstanceFullName).Title("Instance Full Name");
        columns.Bound(p => p.HostingEnvironment).Title("Hosting Environment").ClientTemplate("#: HostingEnvironment.LocationName #");
        columns.Bound(p => p.SysId);
        columns.Command(command => { command.Edit(); command.Destroy(); });
    })
    .Pageable()
    .Sortable()
    .Scrollable()
    .Filterable()
    .ToolBar(commands => commands.Create())
    .Editable(editable => editable.Mode(GridEditMode.InLine))
    .DataSource(dataSource => dataSource
        .Ajax()
        .Model(model =>
            {
                model.Id(p => p.SysId);
                model.Field(he => he.HostingEnvironment).DefaultValue(new Core.Domain.Entities.HostingEnvironment());
            })
        // Configure CRUD -->
        .Create(create => create.Action("CreateNew", "Instance"))
        .Read(read => read.Action("Read", "Instance"))
        .Update(update => update.Action("Update", "Instance"))
        .Destroy(destroy => destroy.Action("Destroy", "Instance"))
        // <-- Configure CRUD        
     )
)
Tags
Grid
Asked by
Jon
Top achievements
Rank 1
Answers by
Jon
Top achievements
Rank 1
Share this question
or