The job of razor (or any view engine in MVC) is to take data which is usually generated by models, the controller, or some combination therein, and turn it into HTML.
A quick example. Suppose a view's purpose is to welcome the user to the site. Given a user object with a Name property, we might write code like this in the CSHTML file:
This exercise takes you through many of the common code blocks you might need to write given mildly complex data in your view.
Note: If you are coming from ASP.NET WebForms, you've been told for many years that you MUST NOT write code in your ASPX files. Razor is quite different here. But there are equally strong guidelines. The solitary role of code in razor views is to turn data into HTML. That's it.
Repeat this to your self 5 times before you get started!
Role of code in razor views is to turn data into HTML. That's it.
OK, great. Keep that in mind and have a good time. Razor is fun stuff.
GK Digital is an online, collaborative learning platform built from the ground up to be a superior learning experience on the web. It is self-paced and yet supported by both your peers and instructors. We have reimagined what learning should be in a world full of public information such as blogs, YouTube, etc. GK Digital is professional training in the 21st century.