user957178
user957178

Reputation: 631

How to use trim on DropdownlistFor

Benefit Set: </label><br />
                 <%: Html.DropDownListFor(model => model.bvODSMapping.Benefit_Set, Model.BenefitSet,new {id="BSet", style = "width:230px;" })%>

When I am using model=>model.bvODSMapping.Benefit_Set.Trim()

I am getting Value Can not be null.

can anybody help me out how to trim the string?

Thanks

Upvotes: 0

Views: 424

Answers (1)

philipproplesch
philipproplesch

Reputation: 2127

I guess it would be the best to trim the values before passing the model to your view. Nevertheless, this might help:

@Html.DropDownListFor(
  model =>
  model.bvODSMapping.Benefit_Set,
  Model.BenefitSet.Select(
    item => 
    new SelectListItem
    {   
      Selected = item.Selected, 
      Text = item.Text.Trim(), 
      Value = item.Value
    }),
  new { id = "BSet", style = "width:230px;" })

Upvotes: 1

Related Questions