We’ve added a new @model directive with the ASP.NET MVC 3
Beta that provides a cleaner and more concise way to indicate you want to use
strongly-typed model classes within your view files. You can now just
write @model StrongModelType at the top of your Razor view file, and you do not
need to have an @inherits or specify a view base class anymore:
The above syntax is conceptually the same as before (except
with a lot fewer characters). It is easier to read and type.
Below is what a complete Index.cshtml view implementation
might look like to render our original screen-shot above:
One question you might ask is – so what does my view file
derive from then if it isn’t specified? By default, Razor will derive the
view from the System.Web.Mvc.WebViewPage<TModel> base class. You
can optionally override this default base class (as well as the list of code
namespaces that are imported by default within view files) by modifying the
web.config file of your \Views directory. This enables you to keep a
clean (and DRY) syntax within your view files even if you have created a custom
View base class that you want to use.
Note: Visual Studio Code/Markup Intellisense and
Colorization within Razor files aren’t enabled yet with the Beta earlier this
month. You’ll see this show up in a few weeks though – and it will
support full code intellisense for HTML, JavaScript, CSS and C#/VB code within
Razor files.