How to keep the Razor files free of code logic?

I am trying to understand how to apply best practices coding to my Razor files.  I understand that I should keep the Razor files free of code logic, when possible. But often calling C# properties is important to setting the CSS. So do these make sense to accomplish this?

- Move the HTML definition to the Model, or a Helper class.
- Make Model return a property that's the CSS class?

If not, how best can I accomplish the goal of keeping the Razor files free of code logic?

newbiewebSr. Software EngineerAsked:
Who is Participating?
gery128Connect With a Mentor Commented:
Ideally, model should not contain/represent the view/html information.

You should consider writing Helper class that will populate the css/html for you and inject/use it in view.

That would be better approach, and for MVC best practices, I would recommend this link:

newbiewebSr. Software EngineerAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.