This question is locked. New answers and comments are not allowed.
OK, I have officially given up....
I am desperately trying to display a dropdown when adding/editing and item in gridview....
I don't know if my situation is special, but so fat, I have read most of what I could find about grid and dropdown.
Background:
The Controller
(Some code in the controller has been omitted)
One more note - the dropdown.cshtml is very specific in the data, so dont mind the MainGroup-dropdown for now (even though I would like to understand, how I can reuse the Template with a different ViewData-object)
So there it is.....
and I have oficially given up.... The Dropdown doesn't show, neither in create or edit...
I've spend quite a long tme on this I i have come to the conclusion, that I need professional help - so anyone want to catch this?
Regards,
Martin Moesby
I am desperately trying to display a dropdown when adding/editing and item in gridview....
I don't know if my situation is special, but so fat, I have read most of what I could find about grid and dropdown.
Background:
- I created a MVC3 project with EntityFramework 4.1, Database first.
- I added my tables to the EDMX designer.
- I created my poco-objects using the ADO.NET DbContext creator.
- Altered properties in the entity, for which I want a dropdown when creating/editing...
- Created a DropDown.cshtml i the Shared/EditorTemplates
- I created a controller using scaffolding for List, Edit, Create and Delete
- In the create/edit-action of my controller, I created the ViewData-object with my data for the dropdown.
SO far so good... I think I have remembered all the steps.....
OK, heres my code :
The Entity
public partial class Product { public Product() { this.CustomerMargins = new HashSet<CustomerMargin>(); this.Prices = new HashSet<Price>(); } public int Id { get; set; } public string ProductNumber { get; set; } public string ProductName { get; set; } public string CommonProductNumber { get; set; } [UIHint("DropDown")] public int ProductGroup_Id { get; set; } [UIHint("DropDown")] public int ProductMainGroup_Id { get; set; } public virtual ICollection<CustomerMargin> CustomerMargins { get; set; } public virtual ICollection<Price> Prices { get; set; } public virtual ProductGroup ProductGroup { get; set; } public virtual ProductMainGroup ProductMainGroup { get; set; } }}The virtual properties er navigational properties...
The View
@model IEnumerable<ProductPriceManagement.Models.Product> @{ ViewBag.Title = "Product";}<h2> Product Management</h2>@(Html.Telerik().Grid(Model) .Name("Grid") .DataKeys(keys => keys.Add(o => o.Id)) .DataBinding(dataBinding => dataBinding .Server() .Select("Index", "Product") .Update("Edit", "Product") ) .Columns(columns => { columns.Bound(o => o.CommonProductNumber).Title("Nordic nr").Width(100); columns.Bound(o => o.ProductMainGroup.Description).Title("Main Group").Width(200); columns.Bound(o => o.ProductGroup.Description).Title("Product Group").Width(200); columns.Bound(o => o.ProductNumber).Width(120); columns.Bound(o => o.ProductName).Width(250); columns.Command(commands => commands.Edit().ButtonType(GridButtonType.BareImage)).Width(100); }) .Editable(editing => editing.Mode(GridEditMode.InLine)) .Scrollable(scrolling => scrolling.Enabled(true)) .Sortable(sorting => sorting.Enabled(true)) .Pageable(paging => paging.Enabled(true)) .Filterable(filtering => filtering.Enabled(true)) .Groupable(grouping => grouping.Enabled(true)) .Footer(true))<p> @Html.ActionLink("Create new", "Create", "Product")</p>The DropDown.cshtml
model ProductPriceManagement.Models.Product@(Html.Telerik().DropDownList() .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty)) .BindTo(new SelectList((System.Collections.IEnumerable)ViewData["ProductGroup_Id"], "Id", "Name", Model.ProductGroup_Id)) )The Controller
// GET: /Product/Createpublic ActionResult Create(){ PopulateGroupLists(); return View();} //// POST: /Product/Create[HttpPost]public ActionResult Create(Product product){ if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return RedirectToAction("Index"); } PopulateGroupLists(); return View(product);}protected void PopulateGroupLists(){ ViewData["ProductGroup_Id"] = new SelectList(db.ProductGroups, "Id", "Description"); ViewData["ProductMainGroup_Id"] = new SelectList(db.ProductMainGroups, "Id", "Description"); ViewBag.ProductGroup_Id = new SelectList(db.ProductGroups, "Id", "Description"); ViewBag.ProductMainGroup_Id = new SelectList(db.ProductMainGroups, "Id", "Description");}One more note - the dropdown.cshtml is very specific in the data, so dont mind the MainGroup-dropdown for now (even though I would like to understand, how I can reuse the Template with a different ViewData-object)
So there it is.....
and I have oficially given up.... The Dropdown doesn't show, neither in create or edit...
I've spend quite a long tme on this I i have come to the conclusion, that I need professional help - so anyone want to catch this?
Regards,
Martin Moesby