Default Item in Dropdown for Custom List

2 posts, 1 answers
  1. Emily
    Emily avatar
    4 posts
    Member since:
    Feb 2015

    Posted 23 Sep 2015 Link to this post

    I have a Target field in my PopupEditor that's using custom List to display a dropdown in the View. I want the first item in the custom list (Self) to show as the default value in the dropdown.


    @Html.LabelFor(model => model.Target, new { @class = "col-sm-5 control-label" })
        @Html.EditorFor(model => model.Target)


    public ActionResult Index()
        ViewData["Targets"] = ixList.Targets();
        return View();

    Custom List (ixList):

    public static List<TargetsModel> Targets()
        List<TargetsModel> targets = new List<TargetsModel>();
        targets.Add(new TargetsModel { Description = "Self", Target = "_self" });
        targets.Add(new TargetsModel { Description = "Blank", Target = "_blank" });
        return targets;


    public string Target { get; set; }  // target = _blank, _self


    How would I go about setting the first item Self to the default value? Right now the default value appears to be null.



  2. Answer
    Vladimir Iliev
    Vladimir Iliev avatar
    2190 posts

    Posted 28 Sep 2015 Link to this post

    Hi Emily,

    You achieve the desired behavior by setting the default value directly in the Grid DataSource by passing the first item from the ViewData array of "Targets":

    .DataSource(dataSource => dataSource
        .Model(model => {
            model.Id(p => p.ID);
            model.Field(p => p.ID).Editable(false);
            model.Field(p => p.Target).DefaultValue(((List<TargetsModel>)ViewData["Targets"])[0].Target);

    Vladimir Iliev
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top