1

I want to use code beside files for my views in my ASP.NET MVC project. Is there any simple way in Visual Studion 2008 how to add a code beside file to the view?

Note: I know that code besides files are no preferred in ASP.NET MVC but my reason is that I want to give .aspx files to designer and don't want to confuse him nonHTML code as little as possible. More good reasons for doing that can be found here.

Community
  • 1
  • 1
Jakub Šturc
  • 35,201
  • 25
  • 90
  • 110
  • So, do you have any update on that? – Ahmed Feb 04 '10 at 08:05
  • @Galilyou: Sorry no update. This question arise at very early stage of the project. At the end of the day we choose another approach. However I believe your answer is pretty close and since nobody comes with better answer within last year I should accept it. – Jakub Šturc Feb 04 '10 at 10:01

2 Answers2

2

Add a class to your view folder and name it (for example) Foo and make sure that this class inherits ViewPage or ViewPage in case if your View is a strongly typed one.

Then in the aspx markup change the inherits from attribute of the @page directive to Foo.cs

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="Foo" CodeBehind="~/Views/Home/Foo.cs" %>

Hope this helps.

Ahmed
  • 11,063
  • 16
  • 55
  • 67
1

A better bet might be to make your ViewPage inherit a custom class which exposes the stuff you want as protected members or extension methods or whatever.

That said, most decent designers these days understand "don't mess with that section at the top that is in the <% ... %>."

Wyatt Barnett
  • 15,573
  • 3
  • 34
  • 53