I have a view model, controller. The view model has a selectlistitem
property. I am using the selectlistitem
to bring the list in the controller and passing it to view model list property.
In the text of selectlistitem
, I am concatenating three properties. I am passing the list to viewmodel
. I need to iterate through the list in the view and split the text to display it into what I needed. Is there any other approach where I can loop through the selectlistitem
property and split the text?
ViewModel:
Public List<SelectlistItem> Current {get; set};
Controller:
public ActionResult Index()
{
ViewModel model;
model = new ViewModel()
{
Current = Active
};
return View(model);
}
//to get data, a private property
private List<SelectListItem> Active
{
get
{
List<SelectListItem> active = new List<SelectListItem>();
foreach(DomainModel model in domainlist)
{
active.Add(new SelectListItem)
{
Text = model.property + "-" + model.property + "-" + model.property
}
}
return active;
}
}
I get the data back to view model. The text property in selectlistitem
has 3 values combined. I want them to be separate. Is there a way, I can loop through the list item in viewmodel
or controller and split the text rather than doing it in view? Or should i create another viewmodel
and bring it as a list?