I've got an ADO.NET Entity Framework class called Node in a WPF project. I want to use it in a different ASP.NET MVC project within the same solution.
My Node controller:
Public Class NodeController Inherits System.Web.Mvc.Controller Function Display(ByVal id As Guid) As ActionResult Dim db As New WpfApplication1.Model1Entities Dim m As WpfApplication1.Node = (From n In db.Node _ Where n.Id = id _ Select n).First Return View(m) End Function End Class
When I run the project and try to navigate to http://.../Node/Display/[a valid ID]
I get an error on my Display action:
Server Error in '/' Application.
Compilation Error
Compiler Error Message: BC30456: 'Title' is not a member of 'ASP.views_node_display_aspx'.
Source Error:
Line 1: <%@ Page Title="" Language="VB" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage(Of WpfApplication1.Node)" %>
Source File: C:...\MvcApplication1\Views\Node\Display.aspx
I've read that error can be due to a codebehind class naming conflict. But I don't think that's the case here.
Can I not use a Model from a different project to create a strongly-typed ASP.NET MVC View?
Update 1:
I've tried importing the namespace on my Display.aspx page, but none of
<%@ Import Namespace="WpfApplication1" %>
or
<%@ Import Namespace="SolutionName.WpfApplication1" %>
or
<%@ Import Namespace="SolutionName.WpfApplication1.Model1Entities" %>
prevent the error.
Update 2:
I've tried adding the namespace to my Views/Web.config file, but niether
<add namespace="SolutionName.WpfApplication1" />
nor
<add namespace="SolutionName.WpfApplication1.Model1Entities" />
prevent the error.
Update 3:
Since adding the namespace, I do now get this Warning:
Namespace or type specified in the Imports 'SolutionName.WpfApplication1' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.
Is that a clue?
Update 4:
I've moved the model from my WpfApplication1 to a new ClassLibrary1.
I've cleaned up my Controller.
Imports ClassLibrary1 Public Class NodeController Inherits System.Web.Mvc.Controller Function Display(ByVal id As Guid) As ActionResult Dim db As New Model1Entities Dim m As Node = (From n In db.Node _ Where n.Id = id _ Select n).First Return View(m) End Function End Class
I've cleaned up my View.
<%@ Import Namespace="ClassLibrary1" %>
<%@ Page Title="" Language="VB" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage(Of Node)" %>
I no longer see the Warning.
But I still get the runtime error.