My code successfully shows the extenbsive list of "directors" but I cannot see how to have the correct (current) director selected as the form shows??
Im confused about the ajax binding and EVERYTHING?
any help or a reference to an example would be appreciated
heres my code as it stands
<div class="editor-label"> @Html.LabelFor(model => model.Race1.DirectorId) </div> <div class="editor-field"> @(Html.Telerik().DropDownListFor(model=>model.Race1.DirectorId) .Name("DirectorId") .BindTo(new SelectList(Model.Directors, "Value", "DisplayText")) ) @Html.ValidationMessageFor(model => model.Race1.DirectorId) </div>
7 Answers, 1 is accepted
You can check the server edit templates example which shows how to add a dropdownlist in the grid editor template.
Atanas Korchev
the Telerik team
The question posted in this forum was for a combo box/dropdownlist in a simple edit page Is this the same thing??
Also not linked to an actual Employee (in your example, from the EditableOrder.Employee) but rather I only have the EmployeeID in my model
the EmployeeID of which would be selected from a combobox full of the possible Employees in my edit form
Am i missing the point?
Can I still use "UIHint("Employee") even if my field is only EmployeeID??
Also: if using Razor do i still have these templates saved as ascx files??
I have created a simple test project which shows how to use ComboBox UI component in an editor template. Please note the Index.cshtml (Razor) and the Customer.ascx (WebForms). The Editor template which is UserControl can be easily used in a Razor page.
Georgi Krustev
the Telerik team
theres an actionresult that returns JSON data called GetCustomers.... I cant see that used anywhere?
Also what are the requirements for "auto matching" the fields in the editorfor?
For instance, can I have a "BasicListItem" class that just contains "ID" and "name" and fill these with customers/Products
would the "magic" still work or will MVC go looking for "CustomerID" and ProductsID??
ALSO
you use .SelectedIndex in the template?? wouldnt this break the autoselecting of the correct member of the dropdownlist?
GetCustomers Action method was not used in the previously attached test project. It can be used to bind ComboBox UI component in Ajax mode. I have attached the modified test project which shows how to do that.
"auto matching" functionality in the CombBox/DropDownList UI component works like in the Html.DropDownList extension. If ViewData.Eval("Component name") returns value it will be used to select value from the List<SelectListItem>. Depending on the given implementation in the test project, you can select item with JavaScript. I have also add Html.DropDownListFor extension which shows that the correct item is not selected in this case.
Component should be named exactly the same way as the key in the ViewData in order to get "auto matching " functionality.
SelectedIndex will not select different item, because value get from ViewData has bigger priority.
Georgi Krustev
the Telerik team
this works & shows the selected value as per the model's data
<div class="editor-field"> @(Html.Telerik().ComboBoxFor(model => model.Race1.LocationID) .BindTo(Model.Locations as SelectList)) @Html.ValidationMessageFor(model => model.Race1.LocationID)</div>but the changes dont appear in the data back on the controller
similarly for other fields.
the start of this edit view declares
@model WAC_MVC.ViewModels.RaceEditViewModel@{and the post controller action is
[HttpPost]public ActionResult Edit(int id, FormCollection collection){ Race race = db.GetRaceById(id); if (TryUpdateModel(race)) { db.SaveChanges(); return RedirectToAction("Index", new { id = race.RACEID }); } RaceEditViewModel returnVM = new RaceEditViewModel(race); return View(returnVM);}im really not understanding the samples youve sent im sorry
http://stackoverflow.com/questions/1242758/what-is-correct-behaviour-of-updatemodel-in-asp-net-mvc
Seems I had to use the viewmodel as my "tryUpdate" target and all was good
this is contrary to the nerdinner example offered by msdn
so my code is all as above with the alteration to the controller so that:
[HttpPost]public ActionResult Edit(int id, FormCollection collection){ Race Race1 = db.GetRaceById(id); RaceEditViewModel returnVM = new RaceEditViewModel(Race1); if (TryUpdateModel(returnVM)) { db.SaveChanges(); return RedirectToAction("Index", new { id = Race1.RACEID }); } return View(returnVM);}