Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Noor Alam 26 posts 97 karma points
    Sep 05, 2019 @ 11:15
    Noor Alam
    0

    How to remove duplicate value in Umbraco V8

    Please check following code that i am using for Dropdown List bind after split the values in Partial View and in bind dropdownlist i am getting repeated values thats why i want to remove duplicate value in same. Please suggest .

    Partial View Code :-

    foreach (var deposit in Model.Children()) {

                    <div class="content" style="width: 100% !important;">
                        <header>
                            <h3><a href="@deposit.GetProperty("depositRateFile").Value()" target="_blank">@deposit.Name</a></h3>
                        </header>
                    </div>
    
                    string[] categories = deposit.GetProperty("depositRateDate").Value().ToString().Split('/');
    
                    var day = categories[0].ToString();
                    var month = categories[1].ToString();
                    var year = categories[2].ToString();
    
                    var deposityear = year.Split(' ');
                    <option>@deposityear[0].ToString()</option>
    

    ====================================== Output :-

    enter image description here

  • Shaishav Karnani from digitallymedia.com 354 posts 1638 karma points
    Sep 05, 2019 @ 11:36
    Shaishav Karnani from digitallymedia.com
    0

    Hi Noor,

    Can you try var deposityear = year.Split(' ').Distinct();

    Regards,

    Shaishav

  • Noor Alam 26 posts 97 karma points
    Sep 05, 2019 @ 16:32
    Noor Alam
    0

    Getting attached error. Please suggest.

    enter image description here

  • Shaishav Karnani from digitallymedia.com 354 posts 1638 karma points
    Sep 05, 2019 @ 16:43
    Shaishav Karnani from digitallymedia.com
    0

    Try depositYear.elementAt(0)

  • Noor Alam 26 posts 97 karma points
    Sep 05, 2019 @ 16:51
    Noor Alam
    0

    but its not removed duplicate values

  • Noor Alam 26 posts 97 karma points
    Sep 05, 2019 @ 18:57
    Noor Alam
    0

    I have modify the code as below but not getting distinct value and debug mode as attached screen shot i achieve objective . Please suggest.

    List

                    <div class="content" style="width: 100% !important;">
                        <header>
                            <h3><a href="@deposit.GetProperty("depositRateFile").Value()" target="_blank">@deposit.Name</a></h3>
                        </header>
                    </div>
    
                    string[] categories = deposit.GetProperty("depositRateDate").Value().ToString().Split('/');
    
                    var day = categories[0].ToString();
                    var month = categories[1].ToString();
                    var year = categories[2].ToString();
    
                    string[] deposityear = year.ToString().Split(' ');
    
                    list.Add(deposityear[0].ToString());
                }
    
                for (int i = 0; i < list.Distinct().Count(); i++)
                {
                    <option><string>(@list.Distinct()).Items[i]</option>
                }
            }
    

    =====================================

    getting output :

    (System.Linq.Enumerable+

    ============= screen shot getting debug ======================

    enter image description here

Please Sign in or register to post replies

Write your reply to:

Draft