javascriptmvc folder structure with asp.net mvc - asp.net-mvc

It seems to me the first biggest hurdle of fitting javascriptmvc into asp.net mvc, is the folder structure. Has anyone adapted the asp.net mvc folder structure to serve up content files from the folder structure javascriptmvc expects?

using routes.IgnoreRoute("javascriptmvc-3.0.5/{*pathInfo}"); in your route definitions things should work as expected.

Related

In MVC what extension should the view file names have?

I have been given a sample MVC project that contains views with extension .aspx
however when I create a new MVC project using the VS2013 ASP.Net wizard the views have extension .cshtml
Are there 2 kinds of MVC project?
Views in MVC refer to either .cshtml files in C# or .vbhtml files in Visual Basic.
.aspx files are webform files and are not views-- this was the initial approach ASP.NET took to make webform development more similar to desktop application development. These pages are generally included in the route list as actual files, whereas MVC uses controller routes that aren't based on existing files (i.e., the url path doesn't match the file and directory structure like traditional html does), which ultimately serve the views. .aspx files can also have code-behind files to separate the html/aspx markup from the .NET code; those files will have either a .aspx.cs or .aspx.vb extension on them. In an MVC app, these files are also likely to have designer files.
One set of files for an aspx file named MyPage may have the following files:
MyPage.aspx
MyPage.aspx.cs or MyPage.aspx.vb
MyPage.aspx.designer.cs or MyPage.aspx.designer.vb
The files in #3 may be hidden until you select 'show all files' in the project, or may not exist at all in a traditional 'web site' project type. I think you have to upgrade to a 'web application project (Wap)' project type before you can integrate MVC, though I may be wrong. All WAP projects should have these .aspx.designer.xx files.
In MVC what extension should the view file names have?
.cshtml unless you have a reason not to use the Razor view engine with C#.
Are there 2 kinds of MVC project?
The relevant answer is that there are many more than 2 different view engines. Razor was introduce in 2010. The Razor view engine is what comes out of the box in the Visual Studio MVC templates. See ASP.NET MVC View Engine Comparison for more info on more obscure view engines that work with ASP.NET MVC.

Define ashx file in MVC doesn't work

I define a ashx file in MVC4 project in content folder so it doesn't work ?!!
So i have several questions?
1- Can we define ashx file in MVC or it isn't possible?
2-If we can define how can we do that?
Best regards
You can definitely use an .ashx file in MVC. An MVC app is an ASP.NET Web app. You should add the .ashx in the root folder (not the content folder), or in a normal subfolder, as you would in an ordinary ASP.NET web project.

MVC Web Api - barebones minimal project structure

I'm looking at this MVC WebApi starter kit (for Angular/TypeScript)
Ignoring all the client side code, I noticed the author has made a WebApi that is extremely bare bones. Has has taken out most scaffolding including _ViewStart.cshtml, _Layout.cshtml, and forgoed the convention of controllers in Controllers folder and views in View folder under subdirectory with same name of controller, etc.
He added some interesting Routing and Validation classes that I havent seen before in a Core folder and put controllers in Api folder and Views directly into Views folder with an Index.cshtml at the root.
It's very clean and barebone project structure for a standalone web api that will do nothing except serve data to a client heavy application. I kind of like it this way but before jumping ship I'm wondering what drawbacks this approach has and if I'm actually giving up any core features of the framework by doing it this way. For example, clearly MVC Areas are being given up here in favor of flexibility to create your own view folders structure and seperation of application sections (I'm okay with getting rid of MVC Areas I rarely used them anyways). Another thing is I don't think a Controller action method can return View() and it will find it in the Views folder by convention of the controller name. I'm also okay with that since I will only be serving JSON data and will use 100% client side templating.
Are there any other core features that are being abandoned that I'm missing that may make me regret going with this project structure?
When I create Web APIs that are hosted in IIS, the only files in my web application are web.config, global.asax and global.asax.cs. Everything else is not required.
Take a look at this template if you haven't already before you decide how to structure your ASP.Net MVC / Angular project:
http://visualstudiogallery.msdn.microsoft.com/5af151b2-9ed2-4809-bfe8-27566bfe7d83
You can always add components into your project later, so I wouldn't seat it too much. I like to start with a lean/mostly empty project first and add things myself so that I fully understand what I'm adding.

Changing default directory structure in asp.net mvc

I am working on asp.net mvc project which is quite large in size. I am new to the MVC stuff.
As Asp.Net MVC have default folder structure Controller, Views or Model so can we change this structure. what if instead of Controller i have different folder? Is it possible?
Although it is possible to change the LocationFormats of a view engine, this isn't recommended as it messes with the standard MVC conventions.
Instead, you should consider using Areas for each of your major 'modules' of functionality.
Your folder structure will then be similar to:
/(MVC Root)
/Areas
/Sales
/Controllers
/Views
/Financials
/Controllers
/Views
etc.

Why are there designer files (*.designer.cs) in ASP.NET MVC?

What's the point of the auto-generated 'designer' files in ASP.NET MVC Web Apps?
I'm trying out ASP.NET MVC (coming from ASP.NET Webforms projects), so I'm used to just having the one code file with each ASP.NET markup file (.aspx, .ascx etc.). Can I use the code beside model with MVC Apps instead as less files seems simpler?
Thanks.
The designer.cs files are a hold over from Web Application projects (which MVC is a derivative of). Along with the regular code behind files, they are no longer needed with the latest MVC RC.

Resources