When I am trying to edit or add in grid using Custom Dropdown Binding... in the code behind the viewmodel is not binding properly. It shows Id as Null and Name as Collection.
Could any one please solve this problem?
Thanks in Adv.
My View Model:
My Editor Template
My Grid Binding
When I am trying to edit, the datasource in Json Format
and in the code behind(Web APi)when I trying to capture in the model it shows like this(Plz check the attachment)
Could any one please solve this problem?
Thanks in Adv.
My View Model:
public class CategoryViewModel
{
public int? CategoryId { get; set; }
public string CategoryName { get; set; }
}
@model ViewModel.Query.CategoryViewModel
@(
Html.Kendo().DropDownListFor(m => m)
.DataTextField("CategoryName")
.DataValueField("CategoryId")
.BindTo((System.Collections.IEnumerable)ViewData["categories"])
)
@(Html.Kendo().Grid<
TestCategoryQueryModel
>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.Id);
columns.Bound(p => p.CatName);
columns.Bound(p => p.CatDescription).Filterable(false);
columns.Bound(p => p.CatImg).Filterable(false);
columns.Bound(p => p.Categories).Filterable(false);
columns.Bound(p => p.CatPublish).Filterable(false);
columns.Bound(p => p.CatShowOrder).Filterable(false);
columns.Bound(p => p.CatSubjectToAcl).Filterable(false);
columns.Bound(p => p.CatSearchKeys).Filterable(false);
columns.Command(c =>
{
c.Edit();
c.Destroy();
});
})
.ToolBar(tools =>
{
tools.Create();
})
.Sortable()
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Pageable(pageable =>
{
pageable.Refresh(true);
pageable.PageSizes(true);
})
.Filterable()
.Groupable()
.ColumnMenu()
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
model.Id(p => p.Id);
model.Field(p => p.Categories).DefaultValue(ViewData["defaultCategory"] as CategoryViewModel);
})
.Events(events=>events.Error("error_handler"))
.Read(read => read.Url("/api/TestCategoryWebApi").Type(HttpVerbs.Get))
.Create(create => create.Url("/api/TestCategoryWebApi").Type(HttpVerbs.Post))
.Update(update => update.Url("/api/TestCategoryWebApi").Type(HttpVerbs.Put))
.Destroy(destroy => destroy.Url("/api/TestCategoryWebApi").Type(HttpVerbs.Delete))
))
({$id:
"2"
, Id:1, CatName:
"Category Name1"
, CatDescription:
"Test Description1"
, CatImg:
"Image1"
, CatParentId:1, CatSubjectToAcl:
false
, CatSearchKeys:
"Test 1"
, CatPublish:
true
, CatShowOrder:1, Categories:{CategoryId:3, CategoryName:
"Category Name11"
}})