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

KendoUI - Uncaught ReferenceError when creating a new row.

1 Answer 177 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 01 Jul 2012, 10:38 AM
Hi,

I get the error "Uncaught ReferenceError: Customer is not defined" when i try and create a new row on the grid. It will display the data correctly.

My grid is defined like this ...

@(Html.Kendo().Grid(Model)
    .Name("OrderGrid")
    .Columns(columns =>
    {
        columns.Bound(o => o.OrderId).Title("Order Id");
        columns.Bound(o => o.Customer.CustomerName).Title("Customer Name");
        columns.Bound(o => o.AccountManager).Title("AccountManager");
        columns.Command(command => { command.Destroy(); command.Edit(); });
    })
    .Pageable()
    .Editable(editable => editable.Mode(GridEditMode.PopUp))
    .ToolBar(commands => commands.Create().Text("New Order"))
    .Filterable()
    .DataSource(dataSource => dataSource
        .Ajax()
        .Model(model => model.Id(o => o.OrderId))
        .Events(events => events.Error("error"))
        .Create(create => create.Action("Orders_Create", "Order"))
        .Read(read => read.Action("Orders_Read", "Order"))
        .Update(update => update.Action("Orders_Update", "Order"))
        .Destroy(destroy => destroy.Action("Orders_Destroy", "Order"))
    )
)

And my models are like this...

public class Order
    {
        public int OrderId { get; set; }
        public int CustomerId { get; set; }
        public string AccountManager { get; set; }
        public Customer Customer { get; set; }
    }
 
public class Customer
    {
        public int CustomerId { get; set; }
        [Required]
        public string CustomerName { get; set; }
        [Required]
        public string Address1 { get; set; }
        public string Address2 { get; set; }
        public string Address3 { get; set; }
        public string City { get; set; }
        public string County { get; set; }
        [Required]
        public string Postcode { get; set; }
 
        private ICollection<Order> Orders { get; set; }
    }


I guess this is because CustomerName is stored in a different table, but I can't figure out why. Any help would be great, I am so lost on this one.

Thanks,
Chris

1 Answer, 1 is accepted

Sort by
0
Chris
Top achievements
Rank 1
answered on 03 Jul 2012, 08:01 AM
I am away from my main PC.

But would changing

columns.Bound(o => o.Customer.CustomerName).Title("Customer Name");

to

columns.Bound(o => o.Customer).ClientTemplate("#=Customer.CustomerName#");

help at all?

Just an idea!

Thanks
Chris
Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Answers by
Chris
Top achievements
Rank 1
Share this question
or