Asp.NET MVC 2 Preview 2: Area's aspx namespace problem - asp.net-mvc

I am now testing the new feature of MVC 2 Preview 2 called Areas within one project.
Followed the MSDN article as well as the relase notes document I have created the Areas folder, then area's name folder, then Controllers and Views folders within that.
Of course the route class was added and it works.
Then I have moved one of the controllers and it's view folder to that new area.
And it fails to run aspx page on the first line:
<%# Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<OtherReferencedProjectNamespace.Entity>" %>
with the syntax parser message
"Cannot load the type: OtherReferencedProjectNamespace.Entity" /example entity name here/
Looks like there are no references to namespaces used previously without any problems! Does the code moved into an area have separate namespace references?
No reference changes were made to the project, just moved one of the controllers with it's view files into an area.
I have no explanation for that yet, have you got an idea?

OK - found it! Had to copy Web.config from root Views directory to the area Views folder.

Related

MVC .NET Core 2.0 - _Layout static files do not load for action methods of a controller

I started a new project in VS 2017 and created a ASP.NET Core 2.0 web application (Model View Controller). Then I've changed the conent of the _Layout.cshtml to the interface I want to use (included #Renderbody etc.) and included all the static content it requires in the wwwroot and save and Ctrl+F5 and the layout shows with all the correct formatting and functionality. No problem so far:
However from this point forward none of the static content files of the _Layout shows in any other view. So for example if I visit any of the following URLS:
http://localhost:52786/home/
http://localhost:52786/home/index
http://localhost:52786/home/about
http://localhost:52786/home/contact
I see this:
Startup.cs already has app.UseStaticFiles() in Configure()
So it sounds like you may have your HTML body content in the wrong place. With ASP.NET MVC &ASP.NET Core MVC, the HTML for each page is served up from the /Views directory (by the Home controller by default), not from the /wwwroot, and it is C# HTML (.cshtml) just like the _Layout.cshtml file. Things like images, static javascript etc. are what's typically located in the /wwwroot directory as these are the parts of your website that are client side instead of server-side.
Try replicating your index, about and contact HTML content as .cshtml files under the /Views/Home directory, replacing whatever's there in the template, except for #{ViewData["Title"] = "Home";} located at the top. The layout template should then serve these as the body content (where #renderbody... is in _Layout.cshtml).
If this still doesn't work I'll need a bit more info about what you've changed from the default template. Hope this helps!
Thank you James for your response. I figured it out and it's actually a noob mistake which I'm posting so that other new developers don't get caught in it.
When you want to reference the content in the wwwroot folder if you reference them without "~/" before the name of the directory it works for the _Layout page which fooled me to think it should work for other parts of the application but you should include "~/" before the folder names explicitly otherwise the static files will be un reachable.

The Controller folder is empty after installing the RoadKill wiki engine

I have installed Roadkill Wiki engine (2.0.275), but i am facing these problems:-
when i run the project using visual Studio 2012 , i got the following message, on the home page:-
You have no mainpage set
To set a main page, create a page and assign the tag 'homepage' to it.
Also i have noted that the Controller folder is empty, while the View folder do have sub folders. so do i have to create the controller classes manually ?
Thanks
The main page message is from you having no pages created in the Wiki, at least with the "homepage" tag - that's how Roadkill picks out the homepage page.
The structure of the project is slightly, or infact completely different, from the standard MVC template. All C# code including controllers and models can be found in Roadkill.Core. All views, CSS and Javascript (or Typescript) is found in Roadkill.Web.
So to find the controllers and models, have a look in:
Roadkill.Core
- MVC
- Controllers
- Models

Where are cshtml files and Controllers in Umbraco with Mvc?

I've just installed Umbraco 6.1.6 making sure to have this setting in the \Config\umbracoSettings.config file before starting the install process.
<defaultRenderingEngine>Mvc</defaultRenderingEngine>
The site has installed fine, and runs fine, but the site is still full of .aspx and .ascx files. What gives? Shouldn't it have created .cshtml files for views, layouts and Controllers and stuff?
Or have I misunderstood and that is up to the user to put in?
Cheers,
-- Lee
Some part of umbraco will still use UserControls.
Try making a new documentType, that will create a view that matches that doctype
You can overrule the default Controller by creating a Controller with the same name.
Remember to inhert from.
public class NameOfTheDocTypeController : Umbraco.Web.Mvc.SurfaceController

Two web.configs?

ASP.Net MVC applications has two web.configs. One in the root folder and one in the Views folder. Why?
From Pro ASP.NET MVC 2 book:
/Views/Web.config:
This is not your application’s main
Web.config file. It just contains a
directive instructing the web server
not to serve any *.aspx files under
/Views (because they should be
rendered by a controller, not invoked
directly like classic Web Forms *.aspx
files). This file also contains
configuration needed to make the
standard ASP.NET ASPX page compiler
work properly with ASP.NET MVC view
syntax.
One reason is to simplify your views and your pages. You can put the compilation or even the masterPageFile declaration from your views in this web.config, for example.
Phil Haack did a great post on this -> http://haacked.com/archive/2009/08/04/views-on-a-diet.aspx

Compile views with enabling MvcBuildViews into MVC 2 Portable Area

I have a big .net mvc 2 project where we are using MvcContrib Portable Area. There is a main web site which load many modules (PA modules).
The main application contains Site.Mater into its ~\Views\Shared folder. each module also has own Site.Master which inherit from that main one.
At the moment we are using something like:
<%# Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" MasterPageFile="~/Views/Shared/Site.Master" %>
After compilation the view handle the main Site.Master right as it is a relative path.
Now I've received a requirement to build views during the compilation. So I've enabled MvcBuildViews = true in each web PA module project.
Of course, I'm getting errors saying "/temp/Views/Shared/Site.Master is not found".
How to keep Portable Area with content embedded and ensure that views do not contain errors?
Any idea?
You can't.
I'm dealing with this same issue and you can't fake the physical location of a file easily.
The only solution is to make a placeholder and removing the non-embedded placeholder file as part of the build process. The benefit of this technique is the non-embedded resource will load a bit faster in development.
Another thing to consider is that loading your views as embedded resources is pretty slow. Having your build process move the centralized "common" views up to the local project will result in better performance for your users.
in case you just want to make sure that everything works fine you could use Watin and write some unit tests that are going to check this

Resources