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.

2
  • So, do you have any update on that? Commented Feb 4, 2010 at 8: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. Commented Feb 4, 2010 at 10:01

2 Answers 2

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.

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

1 Comment

Well this is fine. However it's code behind no code beside. I want to compile .aspx and .cs file into one class.
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 <% ... %>."

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.