Dropdownlist first row for -- Select one --

7 posts, 0 answers
  1. Rudolf
    Rudolf avatar
    3 posts
    Member since:
    May 2012

    Posted 25 Sep 2012 Link to this post

    MVC3 
    I use in Form.cshtml
        @Html.DropDownListFor(m => m.GroupID, ViewData["GroupNameDDL"as SelectList, "-- Select one --")    
    
    in Controller  
    
        ViewData["GroupNameDDL"] = _tbl68SpeciesgroupsRepository.Tbl68Speciesgroups.Select(b => new {
          Id = b.GroupID,       Name = b.GroupName}); TELERIK MVC in EditorTemplate Tbl68SpeciesgroupsForeignKey.cshtml
       @using System.Collections
       @using Telerik.Web.Mvc.UI
       @(Html.Telerik().DropDownList()
            .Name("GroupNameDDL")
            .BindTo(new SelectList((IEnumerable)ViewData["GroupNameDDL"], "ID""Name"))) 
    in GridViewmodel.cs
            [Required]
            [UIHint("Tbl68SpeciesgroupsForeignKey")]
            public int? GroupId { getset; }
    
    In Telerik I use in Form.cshtml
          columns.ForeignKey(b => b.GroupId, (IEnumerable)ViewData["GroupNameDDL"], "ID""Name");
    
    
    How to implement
    "-- Select one --"

        
  2. Carrie
    Carrie avatar
    1 posts
    Member since:
    May 2012

    Posted 26 Sep 2012 Link to this post

    You can try  .OptionLabel("-- select --")
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Rudolf
    Rudolf avatar
    3 posts
    Member since:
    May 2012

    Posted 27 Sep 2012 Link to this post

    Sorry Carrie this dosn't work in Telerik MVC

    columns.ForeignKey(b => b.GroupID, (IEnumerable)ViewData["GroupNameDDL"], "ID""Name").OptionLabel("-- select --");
    
  5. carlg
    carlg avatar
    41 posts
    Member since:
    Jun 2012

    Posted 27 Sep 2012 Link to this post

    In MVC, it's .Placeholder
  6. Rudolf
    Rudolf avatar
    3 posts
    Member since:
    May 2012

    Posted 30 Sep 2012 Link to this post

    Hi carlg
    I don't know how to implement Placeholder at my problem above?


  7. Rudolf
    Rudolf avatar
    3 posts
    Member since:
    May 2012

    Posted 30 Sep 2012 Link to this post

    at Dec. 22.2011 Georgi Krustev wrote

    OptionLabel functionality is in our ToDo list and is scheduled for the next service pack of the Telerik 
    I use Q2 2012 but it is not inside? 
  8. Rudolf
    Rudolf avatar
    3 posts
    Member since:
    May 2012

    Posted 03 Oct 2012 Link to this post

    The solution is very simple

    In Basic EditorTemplate GridForeignKey.cshtml

    @using Telerik.Web.Mvc.UI
    @(Html.Telerik().DropDownList()
        .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(""))
        .BindTo((SelectList)ViewData[ViewData.TemplateInfo.GetFullHtmlFieldName("") + "_Data"])
        .Placeholder("-- Select one --")     !!!!!
    )

    and nothing else

    columns.ForeignKey(b => b.GroupId, (IEnumerable)ViewData["GroupNameDDL"], "ID""Name");
    

    it works well
Back to Top
UI for ASP.NET MVC is VS 2017 Ready