Hi, we use a kendo grid with a popup editor.
@(Html.Kendo().Grid<OrderViewModel>()
.Name("orderGrid")
.Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("OrderDialog"))
.ToolBar(x => x.Create().Text("Add Order"))
.Columns(columns =>
{
columns.Bound(column => column.OrderID);
columns.Bound(column => column.Name);
columns.Command(column =>
{
column.Edit();
column.Destroy();
}).Width(230);
})
.Events(x => x.Edit("onGridEdit"))
.DataSource(ds => ds.Ajax()
.Read(r => r.Url("/Orders/Index?handler=ReadOrder"))
.Update(u => u.Url("/Orders/Index?handler=UpdateOrder"))
.Create(c => c.Url("/Orders/Index?handler=CreateOrder"))
.Destroy(d => d.Url("/Orders/Index?handler=DestroyOrder"))
.Model(m =>
{
m.Id(id => id.OrderID);
})
.PageSize(10)
)
.Pageable()
)
The OrderDialog looks something like this
@model Models.OrderViewModel
<div class="k-edit-label">
@Html.LabelFor(m => m.Name)
</div>
<div class="k-edit-field">
@Html.TextBoxFor(m => m.Name, new { @class = "form-control" })
</div>
...
We would like to be able to hide some fields in the editor if the entity being edited is new (which can be determined by the OrderID). This can be achieved by using the edit event of the grid, but we would rather like to do it based on a model property, like this:
@model Models.OrderViewModel
@if(Model.OrderID == 0)
{
<div class="k-edit-label">
@Html.LabelFor(m => m.Name)
</div>
<div class="k-edit-field">
@Html.TextBoxFor(m => m.Name, new { @class = "form-control" })
</div>
}
Is this possible? When debugging, it seems the editor is initialized with a null model, so that the line above crashes.