I am trying to implement a strongly typed master page and using this page as an example:
How to create a strongly typed master page using a base controller in ASP.NET MVC
I have the following declaration in my masterpage:
<%# Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage<InsTech.ForeSight.Web.Mvc.ModelBase>" %>
When I try to run I get:
Parser Error Message: Could not load type 'System.Web.Mvc.ViewMasterPage<InsTech.ForeSight.Web.Mvc.ModelBase>'
I am not really sure why it can't find the type. When I use the ViewMasterPage class everything is okay, but when I try to use the generic version it bombs.
Any Suggestions
Is InsTech.ForeSight.Web.Mvc.ModelBase in another assembly? if so, is it referenced?
Is InsTech.ForeSight.Web.Mvc.ModelBase abstract?
I got this error when my MVC Master page was outside the 'Views' folder (with my normal Web forms master pages), moving it there solved this error for me.
Edit: Sorry I didn't see #Whoiskb already posted the same answer in the comments up there. Just leaving this answer for people who don't read all the comments :)
Related
I'm wondering does the latest release of MvcContrib work with the Razor view engine? I referenced the MvcContrib assembly and the FluentHtml assembly, then I added the required namespace to the ~/View/Web.config as suggested here by Darin. But still, no matter how much I try use the FluentHtml extensions in my views, it doesn't work. (nothing shows up in intellisense when I start with a dot after the html helper)
Am I missing anything?
P.S: this is the first time I use MvcContrib.
I wrote a short blog that post covers using FluentHtml with Razor.
Regarding intellisense, you will only get intellisense for FluentHtml methods on "#this." (not "#Html.") and it only list the strong-typed helpers on views that implement IViewModelContainer<T> (such as ModelWebViewPage<T>). Another possible issue is Resharper. There is a workaround for that.
I´m using mvccontrib and following darin answer it has to work. The steps I followed were:
copy-pasted in bin folder mvccontrib.dll and mvccontrib.fluent.dll
make a reference in references to those dll creating a reference for mvccontrib and mvccontrib.fluent.
two namespaces with the following names:
add namespace="MvcContrib"
add namespace="MvcContrib.FluentHtml"
in my controller I include using MvcContrib.Pagination;
finally I used in my view:
#using MvcContrib.UI.Pager
#using MvcContrib.Pagination
and rebuild.
hope it helps..
Ive got a project that has got an application.spark and a html.spark that contains all the masterpage markup. The views work fine, but I need to create an isolated page that has no relation at all with the masterpages. Is it possible or will I need to have another nested masterpage?
Thanks
Did you try http://sparkviewengine.com/documentation/master-layouts using:
<use master=""/>
i keep getting Compilation errors when i try to do this . .is there anyway to do this inside the site.master file?
Did you add the master page as an MVC master page?
The Url property that you'rew trying to use comes from the MVC framework's ViewMasterPage class. If you added a regular master page, you need to make it inherit from ViewMasterPage. To do this, change the first line to
<%# Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
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...
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" %>
Assuming you don't have any code in your codebehind, why don't you point them all to one codebehind file?
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.
Not entirely sure what's going on here; any help would be appreciated.
I'm trying to create a new .NET MVC web app. I was pretty sure I had it set up correctly, but I'm getting the following error:
The type 'System.Web.Mvc.ViewPage' is ambiguous: it could come from assembly
'C:\MyProject\bin\System.Web.Mvc.DLL' or from assembly
'C:\MyProject\bin\MyProject.DLL'. Please specify the assembly explicitly in the type name.
The source error it reports is as follows:
Line 1: <%# Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
Line 2:
Line 3: <asp:Content ID="indexContent" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
Anything stand out that I'm doing completely wrong?
I suppose you named one of your page "ViewPage" is that the case?
And like #Jonathan mentioned, this smells:
Inherits="System.Web.Mvc.ViewPage"
On my MVC application, all the view pages have this instead:
Inherits="MySite.Views.Pages.Home"
Or something along the line. Your aspx page markup should have "Inherits" point to your code-behind class name, not the actual class that it is inheriting. The attribute name is rather misleading but its an artifact of earlier days.
Are you using a CodeBehind file, I don't see CodeBehind="" attribute where you are specifying the Inherits from? Then you have to point inherits to the class name of the codebehind.
Example:
<%# Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="MvcApplication4.Views.Home.Index" %>
Make sure the Inherits is fully qualified. It should be the namespace followed by the class name.
I'm running ASP.NET MVC Beta and also encountered this error.
It came about while I was trying to remove the code behind file for a view. I removed the "CodeBehind" attribute in the #Page directive and changed the "Inherits" attribute to point to System.Web.Mvc.ViewPage, but left the actual aspx.cs code behind file untouched in my project.
At this point, if I tried to run my project, I got the error you mentioned.
I resolved this error by deleting the aspx.cs (code behind) file for the view from my project.
Check your assembly references to System.Web.Mvc in web.config.
Mine were explicitly specifying 2.0.0.0, but my project referenced 3.0.0.0
This error usually indicates a class naming conflict. You are referencing two namespaces or you created a class with the same name in another namespace that you are using. I would start by looking at what that could be.
Inherits="System.Web.Mvc.ViewPage"
I'd imagine that this should be pointed at your View codebehind file class, not at the base ViewPage class.
Open up C:\MyProject\bin\MyProject.DLL in Reflector and look for ViewPage to see if you've defined one by accident.
No this should be a structural error message.
Check http://trikks.wordpress.com/2011/08/26/the-type-is-ambiguous-it-could-come-from-assembly-or-from-assembly-please-specify-the-assembly-explicitly-in-the-type-name/
I had the same exact error this week.
My Webform.aspx file had a generated designer.cs file. In this file the class was actually named "ViewPage". Delete the designer file, or move the class contents to the webform.aspx.cs file and my error was gone.
Just putting it out there in case someone had this error.