How to keep the Razor files free of code logic?

Posted on 2011-10-20
Last Modified: 2012-05-12
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?

Question by:newbieweb
    LVL 9

    Accepted Solution

    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:


    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now