get t

2 posts, 1 answers
  1. Daniel
    Daniel avatar
    192 posts
    Member since:
    Mar 2012

    Posted 22 Jan 2013 Link to this post

    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.
  2. Answer
    Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 24 Jan 2013 Link to this post

    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!
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top