I am creating a custom HTML helper with an expression to draw a tag cloud where the data that falls into the tag cloud comes from the expression. I will let the code say here:
Show model
public class ViewModel { public IList<MyType> MyTypes { get; set; } public IList<MyOtherType> MyOtherTypes { get; set; } }
View
<div> @Html.TagCloudFor(m => m.MyTypes) </div> <div> @Html.TagCloudFor(m => m.MyOtherTypes) </div>
Assistant
public static MvcHtmlString TagCloudFor<TModel, TProperty>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TProperty>> expression) where TProperty : IList<MyType> where TProperty : IList<MyOtherType> {
I quickly looked around and did the usual Google searches, but I can’t find such an answer. I assume it is somewhere in the scope of expression.Compile().Invoke() , but I'm not sure if the correct parameters should pass.
I should also note that MyType and MyOtherType have a similar Id property, but there is no inheritance, they are completely separate objects, so I hold back my TProperty as IList<MyType> and IList<MyOtherType> . I am going the wrong way here, I feel how it should be obvious, but my brain is not playing.
source share