user335160
user335160

Reputation: 1362

create a htmlhelper to split the text

I have a field in the table that contains this value "American|African|Asian". I want to get the value form the field and split the text and bind it in the dropdownlist. I am using MVC 3.

So far I have this one:

public static SelectList SplitText(this HtmlHelper html, string  texttosplit, string seperator)
{
  return  new SelectList(texttosplit.Split('|'));
}

But I don't know how to bind it in the dropdownlist

@Html.DropDownListFor(model => model.EM_opt1Values, @Html.SplitText(this will have an error it will not accept model => model.EM_opt1Values) )

Upvotes: 1

Views: 272

Answers (1)

Iridio
Iridio

Reputation: 9271

I think the error is in capital M.

@Html.DropDownListFor(model => model.EM_opt1Values, @Html.SplitText(Model.EM_opt1Values))

The value should be taken from the Model of the page, not from the model variable you define inside the lambda. I can not verify it ATM, but I'm positive this should do it.

Upvotes: 1

Related Questions