tags:

views:

175

answers:

3

I think this is a namespace issue, and the answer is probably dead simple, but I'm new at this MVC stuff.

I have multiple views named "Index." This was not a problem until I tried to create a new, strongly-typed view named "Index."

(For what its worth, I'm trying to follow along with the steps in the NerdDinner sample, but in VB instead of C#.)

When I added the strongly-typed view named "Index," the compiler threw this error:

Base class 'System.Web.Mvc.ViewPage(Of System.Collections.Generic.List(Of Models.User))' specified for class 'Index' cannot be different from the base class 'System.Web.Mvc.ViewPage' of one of its other partial types.

Can someone enlighten me on why this is happening, and what I can do to alleviate the problem?

Thanks in advance.

VIEW:

<%@ Page Title="" Language="VB" MasterPageFile="~/Views/Shared/Site.Master" 
         AutoEventWireup="false" CodeBehind="Index.aspx.vb" 
         Inherits="SampleSite.Index" %> 
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"> 
</asp:Content>

Code Behind:

Imports System.Web.Mvc 
Imports System.Collections.Generic 

Partial Public Class Index Inherits System.Web.Mvc.ViewPage(Of List(Of SampleSite.Models.User)) 
End Class
+1  A: 

I would think you'll need to inherit from ViewPage(Of List(Of SampleSite.Models.User)) in your page definition:

<%@ Page Title="" Language="VB" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="false" CodeBehind="Index.aspx.vb" Inherits="System.Web.Mvc.ViewPage(Of List(Of SampleSite.Models.User))" %>

Does it work that way??

Your strongly-typed ViewPage must inherit from the "ViewPage(Of T)" basic generic type - where the T is the type of the data you want to display in your view page (the "view model").

Marc

marc_s
A: 

If you say you have multiple "Index pages" then the problem is that all have the same namespace. You have Index(a) derived from ViewPage and Index(b) derived from ViewPage of List(..), since the classes are declared partial and have equal namespaces the compiler tries to put them together in one class but is not possible since they don't inherit from the same base class.

Do this: Index (a) -> Inherits="SampleSite.Index" Index (b) -> Inherits="SampleSite.XXXXXXX.Index" and modify the code behind accordingly.

Ariel Popovsky
A: 

I figured it was just a namespace issue. I wrapped the offending Index class in a namespace like below and it solved the problem. Not sure if this is the correct way to solve this problem, but it works.

Imports System.Web.Mvc Imports System.Collections.Generic

Namespace SampleSite

Partial Public Class Index
    Inherits System.Web.Mvc.ViewPage(Of List(Of Models.User))

End Class

End Namespace

camainc