0

I trying to use a Razor Helper that does some if statements for me. I'm passing it a list with certain rules and based on that rule a label and input text field are created.

The problem I have is I can't get it to work with a Lambda expression as parameter. It won't recognize the TModel part.

The helper method is as follows:

@helper CreateCheckbox(Expression<Func<TModel, bool>> expression, object htmlAttributes, List<Rule> ruleList)
{    

}

The error I get is: The type of namespace 'TModel' can not be found.

Romano Zumbé
  • 7,893
  • 4
  • 33
  • 55

1 Answers1

0

You have to pick a type for TModel. Because your view doesn't have any generic type parameters, there is no way for it to figure out what type it should substitute in for TModel. You have to give it an actual type to work with.

If that's not an option, you might just make an extension method for the HtmlHelper class, and make it a generic method. See this question for an example of how to do that.

Community
  • 1
  • 1
Tim Copenhaver
  • 3,282
  • 13
  • 18