This is a migrated thread and some comments may be shown as answers.

Dropdownlist first row for -- Select one --

6 Answers 1466 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Rudolf
Top achievements
Rank 1
Rudolf asked on 25 Sep 2012, 01:42 PM
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 --"

    

6 Answers, 1 is accepted

Sort by
0
Carrie
Top achievements
Rank 1
answered on 26 Sep 2012, 11:26 PM
You can try  .OptionLabel("-- select --")
0
Rudolf
Top achievements
Rank 1
answered on 27 Sep 2012, 01:27 PM
Sorry Carrie this dosn't work in Telerik MVC

columns.ForeignKey(b => b.GroupID, (IEnumerable)ViewData["GroupNameDDL"], "ID""Name").OptionLabel("-- select --");
0
carlg
Top achievements
Rank 1
answered on 27 Sep 2012, 02:10 PM
In MVC, it's .Placeholder
0
Rudolf
Top achievements
Rank 1
answered on 30 Sep 2012, 01:12 PM
Hi carlg
I don't know how to implement Placeholder at my problem above?


0
Rudolf
Top achievements
Rank 1
answered on 30 Sep 2012, 01:13 PM
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? 
0
Rudolf
Top achievements
Rank 1
answered on 03 Oct 2012, 10:44 AM
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
Tags
DropDownList
Asked by
Rudolf
Top achievements
Rank 1
Answers by
Carrie
Top achievements
Rank 1
Rudolf
Top achievements
Rank 1
carlg
Top achievements
Rank 1
Share this question
or