Dropdown list select item

Topics: Customizing Orchard
Nov 21, 2011 at 4:38 AM


I have use dropdownlist as following way

My controller

public ActionResult Edit(int Id)
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage Categories")))
                return new HttpUnauthorizedResult();

            var Categories = Services.ContentManager.Query<CategoryPart, CategoryPartRecord>();

            var results = Categories
               .Slice(0, 100)

            var Category = _CategoryService.Get(Id, VersionOptions.Latest);
            if (Category == null)
                return HttpNotFound();

            dynamic model = Services.ContentManager.BuildEditor(Category);

            ViewData["CategoryID"] = results.Select(c => new SelectListItem
                Text = c.Name,
                Value = c.Id.ToString()


This is my view

    @Html.DropDownList("m.CategoryParentID", (IEnumerable<SelectListItem>)ViewData["CategoryID"], "Select a Category")


When i click edit i cant see existing 

CategoryParentID in the list. its always  
"Select a Category"

How can i select existing id to default


Nov 23, 2011 at 11:59 PM

That's an ASP.NET MVC question. There is a Selected property on SelectListItem that you can set.