user1228
user1228

Reputation:

Remove the *.cs, *.Designer.cs codebehind files?

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...

Upvotes: 2

Views: 3341

Answers (3)

Sumit
Sumit

Reputation: 353

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

Upvotes: 2

Chris Sutton
Chris Sutton

Reputation: 2781

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" %>

Upvotes: 4

Wyatt
Wyatt

Reputation: 1366

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.

Upvotes: 0

Related Questions