Hi guys,
I have a mvc view (still a pretty standard one) to edit one of my entities..
the model is a view model because the actual table (using EF) has a cross table to a child entity and I dont want to bother with it.
so my wiew model is:
and the custom template for the list of functions is:
at last my action looks like:
now, when I hit the save button of the view, the function list is always null or empty...
What am I doing wrong?
Thanks
Fabio
I have a mvc view (still a pretty standard one) to edit one of my entities..
@using (Ajax.BeginForm("Edit", "Role", new AjaxOptions() { HttpMethod = "POST", UpdateTargetId = "ajaxRoleEditForm", OnSuccess = "OnRoleUpdated" })) { @Html.AntiForgeryToken() @Html.ValidationSummary(true) <fieldset> <legend>ROLE_T005</legend> @Html.HiddenFor(model => model.ID) <div class="editor-label"> @Html.LabelFor(model => model.Name) </div> <div class="editor-field"> @Html.EditorFor(model => model.Name) @Html.ValidationMessageFor(model => model.Name) </div> <div class="editor-label"> @Html.LabelFor(model => model.Description) </div> <div class="editor-field"> @Html.EditorFor(model => model.Description) @Html.ValidationMessageFor(model => model.Description) </div> <div class="editor-label"> @Html.LabelFor(model => model.Functions) </div> <div class="editor-field"> @Html.EditorFor(model => model.Functions) </div> <p> <input type="submit" value="Save" /> </p> </fieldset> }the model is a view model because the actual table (using EF) has a cross table to a child entity and I dont want to bother with it.
so my wiew model is:
public class RoleViewModel { public int ID { set; get; } public string Name { set; get; } public string Description { set; get; } [UIHint("FunctionMultiSelectTemplate")] public IList<FUNCTION_T008> Functions { set; get; } }and the custom template for the list of functions is:
@model IList<Lme.WQ2.AccessControl.Dal.FUNCTION_T008>@(Html.Kendo().MultiSelect() .Name("FunctionMultiSelectTemplate") .Placeholder("Select functions...") .BindTo(ViewBag.Functions) .Value(Model) .DataTextField("NAME") .DataValueField("ID") )at last my action looks like:
public ActionResult Edit(int id = 0) { ROLE_T005 role_t005 = db.ROLE_T005 .Include(x => x.ROLE_FUNCTION_T010) .Include(x => x.ROLE_FUNCTION_T010.Select(y => y.FUNCTION_T008)) .SingleOrDefault(x => x.ID == id); RoleViewModel roleViewModel = new RoleViewModel() { ID = role_t005.ID, Name = role_t005.NAME, Description = role_t005.DESCRIPTION, Functions = role_t005.ROLE_FUNCTION_T010.Select(x => x.FUNCTION_T008).ToList() }; ViewBag.Functions = db.FUNCTION_T008.AsEnumerable(); if (role_t005 == null) { return HttpNotFound(); } return View(roleViewModel); }now, when I hit the save button of the view, the function list is always null or empty...
What am I doing wrong?
Thanks
Fabio