Enum DropDownList selected problem

8 posts, 0 answers
  1. Hubert
    Hubert avatar
    4 posts
    Member since:
    Aug 2014

    Posted 27 Jul Link to this post

    I am trying to bind enum dropdownlist ,

    I checked the html source and find two different results.

    First, it shows value="Distribution", the dropdownlist will select correct value.

    <input data-val="true" id="TradeType" name="TradeType" type="text" value="Distribution" data-role="dropdownlist" readonly="readonly" style="display: none;">
    <script>
        jQuery(function(){jQuery("#TradeType").kendoDropDownList({"change":TradeTypeChange,"dataSource":[{"Text":"Clearing","Value":"Clearing"},{"Text":"Contribution","Value":"Contribution"},{"Text":"Distribution","Value":"Distribution"}],"dataTextField":"Text","dataValueField":"Value"});});
    </script>

    Second, it shows value="1", so it will select wrong value. The correct value should be "DueInterest".

    <input data-val="true" id="TDInterestType" name="TDInterestType" type="text" value="1" data-role="dropdownlist" readonly="readonly" style="display: none;">
    <script>
        jQuery(function(){jQuery("#TDInterestType").kendoDropDownList({"dataSource":[{"Text":"CancelInterest","Value":"CancelInterest"},{"Text":"DueInterest","Value":"DueInterest"},{"Text":"ReceiptInterest","Value":"ReceiptInterest"}],"dataTextField":"Text","dataValueField":"Value"});});
    </script>

    I don't how it happened, how could I solved it that second's dropdownlist will select correct value ?

  2. Peter Milchev
    Admin
    Peter Milchev avatar
    144 posts

    Posted 28 Jul Link to this post

    Hello Hubert,

    I tried to replicate the behavior you describe, however, I was not able to. Below you can find the code I used for testing. Would you give it a try and let me know how it works on your end? I would appreciate it if you can modify the sample in a way that the issue is replicated and send it back.

    View:

    @model MyProject.Models.TestingModel
       @using (Html.BeginForm("Test", "Testing", FormMethod.Post))
       {
        @(Html.Kendo().DropDownList()
               .Name("Type")
               .DataTextField("Text")
               .DataValueField("Value")
               .BindTo(EnumHelper.GetSelectList(Model.Type.GetType(), Model.Type))
        )
     
        @(Html.Kendo().DropDownList()
                           .Name("Interest")
                           .DataTextField("Text")
                           .DataValueField("Value")
                           .BindTo(EnumHelper.GetSelectList(Model.Interest.GetType(), Model.Interest))
            )
        <input type="submit"    name="Submit" value="" />
       }

    Controller: 

    public class TestingController : Controller
    {
        public ActionResult Index()
        {
            return View(new TestingModel());
        }
     
        public ActionResult Test(TestingModel model)
        {
            return View();
        }
    }
     
    Models:

    public enum TradeType
    {
        Clearing,
        Contribution,
        Distribution
    }
    public enum InterestType
    {
        CancelInterest,
        DueInterest,
        ReceiptInterest
    }
    public class TestingModel
    {
        public TradeType Type { get; set; }
     
        public InterestType Interest { get; set; }
    }

    Regards,
    Peter Milchev
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Hubert
    Hubert avatar
    4 posts
    Member since:
    Aug 2014

    Posted 28 Jul in reply to Peter Milchev Link to this post

    They are two different views, I try to modify codes as similar  as problem code, but it still works correctly.

    And I also solved my problem , to add ModelState.Clear() in controller.

    //To get data from database with Primary Key
    //model and td, both are the same class TimeDepositInt
    public ActionResult Detail(TimeDepositInt td)
    {
      var model = svc.GetTimeDepositInt(td.PortfolioID,td.TransNo,td.InterestType,td.SettleDate);
      ModelState.Clear();
      return PartialView(model);
    }

    But I am still confused that.

     

  5. Peter Milchev
    Admin
    Peter Milchev avatar
    144 posts

    Posted 01 Aug Link to this post

    Hello,

    I am afraid that the provided information is insufficient to determine the exact reason for the issue. Nevertheless, I am glad that your problem is now solved. 

    Thank you for sharing your solution with the community.

    Regards,
    Peter Milchev
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Hubert
    Hubert avatar
    4 posts
    Member since:
    Aug 2014

    Posted 06 Oct in reply to Peter Milchev Link to this post

    After upgrading  Kendo.Mvc.dll from 2016.1.412.440  to 2016.3.914.545,

    all my enum dropdownlist selects wrong value.

  7. Peter Milchev
    Admin
    Peter Milchev avatar
    144 posts

    Posted 07 Oct Link to this post

    Hello Hubert,

    Would you please create a sample runnable project and attach it in an official support ticket along with more details on the erroneous behavior. Thus, we would be able to investigate the scenario locally and help you more efficiently. 

    Regards,
    Peter Milchev
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  8. Hubert
    Hubert avatar
    4 posts
    Member since:
    Aug 2014

    Posted 07 Oct Link to this post

    I thought I know what's happened , there are two kinds of dropdownlist in our project.

    We convert the Enum properity to IEnumerable<System.Web.Mvc.SelectListItem> and one SelectListItem would be set selected property, but is is not work. 

    The Enum properity has to be used Value(string value)  to  set selected value.

    @model Enum
    @(Html.Kendo().DropDownListFor(m => m)
    .BindTo(Model.GetType().ToSelectList()).Value(Model.ToString())
    )

    the custom datasource selectItem will be 

    <option value="Sell">Sell</option>
    <option value="Buy">Buy</option>

    but the kendo UI will render 

    <option value="0">Sell</option>
    <option value="1">Buy</option>
     

    if the datasource is not Enum properity, it's not necessary to use Value(string value).

    like this

    @Html.Kendo().DropDownListFor(m => m.CurrencyID).BindTo(Shared.CurrencyList)

    The CurrencyID properity is String and  Shared.CurrencyList are also SelectListItem , but Kendo UI will render

    <option value="AUD">AUD</option>
    <option value="USD">USD</option>

     

    of course , I should use 

    @Html.Kendo().DropDownListFor(m => m.CurrencyID).BindTo(Shared.CurrencyList).Value(Model.ToString())

     

     

  9. Peter Milchev
    Admin
    Peter Milchev avatar
    144 posts

    Posted 11 Oct Link to this post

    Hello Hubert,

    Thank you for sharing your observations and solution with us and the community. 

    Regards,
    Peter Milchev
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET MVC is VS 2017 Ready