I am working on a medium sized MVC project.
The View Models have all been pulled out the web assembly to a separate library. One of the data structures is represented by a listbox and has a MultiSelectList property.
The external VM project does not currently have a reference to the System.Web.Mvc assembly.
Should I add the reference?
Should I refactor the code to not have a reference to the MultiSelectList class? If this is the case where does the RawOptionValues property get converted to a MultiSelectList?
public class SelectListPrompt{
public IDictionary<string, string> RawOptionValues { get; set; }
public MultiSelectList OptionValues
{
get
{
return new MultiSelectList(RawOptionValues.ToList(), "Key", "Value");
}
}
}
View models are tightly coupled to your views. This is their purpose. So, yes, they should absolutely know about
System.Web.Mvc. You have put them in a separate class library – great, but while this might not be necessary, if you decide to go that way, this library should know about classes likeSelectListItem,MultiSelectList, … So go ahead and add reference. Don’t refactor your view models – they should work with those classes.What you should be careful about is not to couple your domain models with ASP.NET MVC.