Filtering SelectList for one element but not others

457 Views Asked by At

So I have this on the front end:

<%= Html.DropDownListFor(m => m.FixedComponent.PaymentBusinessDayConvention, DropDownData.BusinessDayConventionList(), "", new { @class = "DontShrink", propertyName = "FixedComponent.PaymentBusinessDayConvention", onchange = "UpdateField(this);" })%>

The DropDownData.BusinessDayConventionList() is defined here:

public static SelectList BusinessDayConventionList()
        {
            return ListBuilder(
                BusinessDayConventionHelper.GetFriendlyName(BusinessDayConvention.Following),
                BusinessDayConventionHelper.GetFriendlyName(BusinessDayConvention.ModifiedFollowing),
                BusinessDayConventionHelper.GetFriendlyName(BusinessDayConvention.Preceding),
                BusinessDayConventionHelper.GetFriendlyName(BusinessDayConvention.Unadjusted));
        }

I want to remove the BusinessDayConvention.Unadjusted option for JUST the one HTML Helper, but not for all of the other ones on the page. How can I do this cleanly?

Thanks!

1

There are 1 best solutions below

0
On BEST ANSWER

Include a parameter to the method:

    public static SelectList BusinessDayConventionList(bool includeUnadjusted)
    {
       var list = ListBuilder(
            BusinessDayConventionHelper.GetFriendlyName(BusinessDayConvention.Following),
            BusinessDayConventionHelper.GetFriendlyName(BusinessDayConvention.ModifiedFollowing),
            BusinessDayConventionHelper.GetFriendlyName(BusinessDayConvention.Preceding));

       if (includeUnadjusted)
       {
         list.Items.Add(BusinessDayConventionHelper.GetFriendlyName(BusinessDayConvention.Unadjusted))
       }

       return list.
    }

You can also have an overload to pass a default value:

    public static SelectList BusinessDayConventionList()
    {
       return BusinessDayConventionList(true);
    }