tags:

views:

189

answers:

3

Im experiencing some craziness that I just can't figure out..

ive created the following class:

public abstract class AbstractView<T> : ViewPage<T> where T : class

which gives me some useful helpers and im using it in my views like this:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="Project.Web.Mvc.AbstractView<Project.Domain.Entities.Example>" %>

This all works fine. Now ive got to make a view which needs lots of complex rendering code, so i want to give my view a codebehind, so i can put all this presentational logic in it.

However, when I do:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="Project.Web.Views.Examples.View" CodeBehind="~/Views/Examples/View.aspx.cs" %>

public class View : Project.Web.Mvc.AbstractView<Project.Domain.Entities.Example>

Model is always null when i debug the view, which subsequently gives me:

"The view 'View' or its master could not be found. The following locations were searched..."

Whats going on?

Andrew

P.S. dont tell me codebehinds are evil. Im writing presentation specific logic, and lots of it. Its not going inline in the aspx.

+2  A: 

You could try using a code-alongside. By that I mean a class deriving from AbstractView<T> that is only used by this one view. It's virtually the same concept as a code-behind. Then just point at that instead of using AbstractView<T>.

Also, your Model won't be hooked up until OnLoad (could be earlier, I've never done it myself) so that could be your problem if you're trying to use it in the constructor.

Otherwise you might want to look at using a ViewModel so that instead of you passing what I assume are raw domain objects, you do the custom formatting in the ViewModel and pass that to AbstractView<T>.

Garry Shutler
A: 

Using View as your class name is probably not a good idea. Using something a more specific.

I take it you ae declaring the class in the namespace specified in the Inherits attribute?

AnthonyWJones
A: 

Ok my bad, the model isnt ready in the codebehind until onload, and i was doing things in the constructor.

Strange that MVC would say "cant find the view" when it clearly can, there was just an exception thrown

Andrew Bullock