views:

1344

answers:

4

Yeah, its a bit on this side of pointless, but I was wondering... I've got all these codebehind files cluttering my MVC app. The only reason why I need these files, as far as I can tell, is to tell ASP.NET that my page extends from ViewPage rather than Page.

I've tried a couple different Page directives changes, but nothing I've found will allow me to identify the base class for the page AND let me delete the codebehind files.

Is there a way to do it?

UPDATE: I'm trying to inherit from a strongly-typed ViewPage! Seems like its possible to inherit from a regular ViewPage...

A: 

Why do you want to delete codebehind files? If you're not using them you should probably rethink your design. ASP.NET without the power of codebehind files is almost like classic ASP :)

In any case, I don't know how to get rid of them.

Ricardo Villamil
He's using ASP.NET MVC. He doesn't need code-behind because his logic is not in the page.
Robert S.
I feel bad for Ricardo. Missed that bit of detail and got knocked a bunch of times...
Will
+1  A: 

Assuming you dont have any code in your codebehind, why dont you point them all to one codebehind file?

Sumit
+3  A: 

Delete the codebehind and use a page directive like this:

<%@ Page Title="Title" Inherits="System.Web.Mvc.ViewPage" Language="C#" MasterPageFile="~/Views/Layouts/Site.Master" %>

Or, if you want to get rid of the codebehind but still want to use strongly typed view, then read this link: http://devlicio.us/blogs/tim_barcz/archive/2008/08/13/strongly-typed-viewdata-without-a-codebehind.aspx

Here is a cut and paste of what this would look like:

<%@ Page Inherits="System.Web.Mvc.ViewPage`1[[ABCCompany.MVC.Web.Models.LoginData, ABCCompany.MVC.Web]]" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" %>
Chris Sutton
A: 

Straight out of the box you should be able to delete the .designer.cs and nothing will break. The other code behind can be useful, for instance if you'd like to strongly type your viewdata.

Wyatt