Filtering SelectList for one element but not others
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);
}
精彩评论