开发者

Filtering SelectList for one element but not others

开发者 https://www.devze.com 2023-02-07 03:17 出处:网络
So I have this on the front end: <%= Html.DropDownListFor(m => m.FixedComponent.PaymentBusinessDayConvention, DropDownData.BusinessDayConventionList(), \"\", new { @class = \"DontShrink\", prop

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),
                BusinessDayConv开发者_JAVA百科entionHelper.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!


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);
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号