I am using version 2011.2.712.340 of the Telerik MVC 3 controls.
I simply want to be able to:
- set the selected value in the dropdownlist to a value coming back from the database
- list the items coming back from the database
- set the selectedindex for saving into the database
I don't know how to set the SelectedIndex and Value properties inside this user control.
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Category>" %>
<%= Html.Telerik().DropDownList()
.Name("CategoryDropDownList")
.SelectedIndex()
.Value(ViewBag.CategoryIdFromDB.ToString())
.DataBinding(databinding => databinding.Ajax().Select("SelectCategories", "Category"))
%>
My View is set up to call the above shared control as follows:
columns.Bound(o => o.ProjectID).Hidden(true);
ViewBag.ProjectID = "<#= ProjectID #>";
columns.Bound(o => o.CategoryID).EditorTemplateName("Category");
The Select statement above in my Shared Editor Template is used to call an Action method in my Category controller as follows.
public ActionResult SelectCategories()
{
ViewBag.CategoryIdFromDB = db.GetCategoryIDByProjectID(ViewBag.ProjectID);
IEnumerable<YeagerTechModel.Category> CategoryList = db.GetCategories();return new JsonResult { Data = new SelectList(CategoryList.ToList(), "CategoryID", "Description") };
}