0

I am learning ASP.NET MVC currently, and looking at the concept of Display and Editor Templates. I am working through a post by Scott Mitchell about Using Templates to Display Boolean Values as Yes/No Options. In it Scott uses .cshtml files within the Shared Folder to store reusable interface templates.

I can't find any way to create .cshtml files in Visual Studio 2008 / ASP.NET MVC 2. Are they an ASP.NET MVC 3 only thing? Would there be a way to build custom templates without upgrading to ASP.NET MVC 3?

0

3 Answers 3

4

cshtml files are razor views. The Razor view engine is part of Asp.NET MVC 3 (Visual Studio 2010 only), yes.

More Information: Introducing “Razor” – a new view engine for ASP.NET

hope this helps

Sign up to request clarification or add additional context in comments.

Comments

2

Similar SO Post here Here is a blog post that may help you get Razor working with MVC 2. Note this is from 2010. There are at least a couple of third party view engines including NHAML and SparkView. I believe that these should work with MVC 2. Here are a coiple of links: comparison of view engines, NHAML at Stephen Walther site

Comments

0

After some research, and reading some of the links from @dknaack and @ashok, I have figured out that I can still create custom templates in MVC 2 using MVC 2 View User Controls, which are .ascx files. A comparable .ascx file to the .cshtml in Scott's blog would look like this:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<% if(ViewData.Model is bool && ((bool)ViewData.Model) == true)
   { %>
   <div>Yes</div>
<%}else{ %>
   <div>No</div>
<%} %>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.