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

get t

1 Answer 75 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 22 Jan 2013, 08:36 AM
Hello,
if i have in razor this dropdownlist
@(Html.Kendo().DropDownList()
          .Name("category")
          .OptionLabel("Select a product...")
          .DataTextField("ProductName")
          .DataValueField("ProductID")
          .HtmlAttributes(new { style = "width:200px" })
          .DataSource(source => source.Read("ProductListData", "Controls"))
          .Events(ev => ev.Change("change"))
      
                                        
)

how can i use in the same view, the value of the dropdownlist using razor syntax?
i was looking for something like @Html.Kendo().DropDownList("category").Value()...

Regards,
Daniel

P.S:i think i put first this same post also to Web UI\DropDownList,please excuse me.

1 Answer, 1 is accepted

Sort by
0
Accepted
Petur Subev
Telerik team
answered on 24 Jan 2013, 06:30 AM
Hello Daniel,

Basically in the View you set the Value for the components from variables/viewmodels passed from the controller, you cannot get the value from the widget you are initializing.

If you pass the value from let's say ViewBag:

 
@(Html.Kendo().DropDownList()
          .Name("category")
          .OptionLabel("Select a product...")
          .DataTextField("ProductName")
          .DataValueField("ProductID")
          .HtmlAttributes(new { style = "width:200px" })
          .DataSource(source => source.Read("ProductListData", "Controls"))
          .Events(ev => ev.Change("change"))
          .Value(ViewBag.SomeValuePassedFromController)
                                         
)

Then you on the other places where you need that value you should again use the ViewBag to retrieve it.

Kind Regards,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
DropDownList
Asked by
Daniel
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question
or