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

get value of dropdownlist using razor

1 Answer 281 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 21 Jan 2013, 01:43 PM

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,

1 Answer, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 23 Jan 2013, 11:28 AM
Hi Daniel, 

You can get the value of the dropdown list using razor syntax from the DropDownList component:
@{
    var ddl = 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")) 
            
    ddl.Render(); //displays the dropdown list
  
    var selected = ddl.ToComponent().Value //gets the selected value
}
or from the model.

I hope this information helps you.
All the best,
Dimiter Madjarov
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
Dimiter Madjarov
Telerik team
Share this question
or