How I create controller folder in mvc6 - asp.net-core-mvc

I Created empty project in mvc6 but theres is no mvc folders , how i ceate model,view,controller folders ?

Because an Aspnet core empty project is truly empty. It is up to you to go about making it.
If you notice it's not just the folder but some of the most used middlewares will also not be there such as app.MVC and app.usemvc in your startup.cs class. The purpose of an empty project is to give you complete control over what you need or don't need.
If you know you definitely need MVC then I suggest you use the ASP.Net MVC template that comes with all the folders and goodies you will need to run MVC.
As for MVC folder structure; controllers and models don't need any special folders. That's just a convention. But views do. So you need to have a Views folder at least.

Related

How do I change Empty Template to Internet Template in MVC 3?

A new MVC Web application has been created with Empty Razor Template. In this template I found that default controller,Model and View are missed. I need to change the template from Empty to Internet Application.
I couldn't find any option in the properties to change Internet controller. How can I do that without creating a new project?
You could create a new project in reverse. Create a new project based on the Internet template, and use a compare tool (I rely heavily on BeyondCompare) to merge the Internet template differences into your existing project.
The difference between Empty Razor Template and Internet Application Template is in two (Account and Home) Controllers, Views that go with them and in different Site.css. You can't simply "switch" between templates.
You can go from Internet Application to Empty, if you delete Account and Home Controllers and corresponding Views. Other way around is a bit more difficult. Use scaffolding to accomplish that.
You can also check differences between templates here.

MVC/Codeigniter file structure

I have been doing a lot of research on MVC and file structure. Mainly I've been looking at how to start a new layout. I have downloaded a few open source applications to take a look at file structure and how files are developed.
In the first application it was set up to use the standard way (at least the way it seems to me) of putting all the controllers, models and views each in their respective folders. This is the way that all the books say to do it.
In the second application, all folders are in a modules_core or modules folder where each controller (at least what I would assume to be controllers) are in a folder in there that contain three folders: controller, model, view.
Which of the two versions is accepted as standard and common practice? Are the two applications different because of versions of Codeigniter?
The standard of Code Igniter is to use those three folders:
Controllers
Models
Views
You can also create sub folders to better separate your files.
Searching a bit, I found that MyClientBase use something called codeigniter-modular-extensions-hmvc that is like a extension for CI.
Modular Extensions makes the CodeIgniter PHP framework modular.
Modules are groups of independent components, typically model,
controller and view, arranged in an application modules sub-directory,
that can be dropped into other CodeIgniter applications.
HMVC stands for Hierarchical Model View Controller.
I don't have experience with hmvc so I cannot tell you what is better. For the standard CI structure, try to separate well in sub-folders (controllers, views and models) related files and try to use helpers to better reuse your code when you need to use functions in more than one place.
I think MyClientBase (which seems to be far from the "standard" exemple), seems to be using HMVC more then MVC.

Where to put the customized profile provider in MVC3

Should the FactoredProfileProvider.cs be placed in App_Code only? What is the standard way to do it? Can I put it under an Area that handles all accounts?
Should the FactoredProfileProvider.cs be placed in App_Code only?
Absolutely not. The App_Code folder should never be used with the web applications model which is what ASP.NET MVC uses. This folder is used only with websites. See web application vs website. So in ASP.NET MVC you could place this file wherever you want, like for example you could create yourself a subfolder called ProfileProviders and put it inside.

How to manage files for a module in ASP.net MVC 3

I built a small module in ASP.net MVC which consists of
a javascript file
a css file
a razor partial view
a c# model class
If I use the standard way to manage the files, I have to spread them in these folders:
/Scripts
/Content/css
/View
/Models
I know that MVC is for separating them and it's fine for the application but i my case I would be happier to have all files somewhere together.
There are area's in MVC but I think that's to big for a small module. All I want is to build a small package in my application for the files of this module.
Any good approach for this? How do you handle this?
/Scripts
/Content/css
/View
/Models
This is just the structure that the default asp.net mvc project template imposes.
You can have any structure you like, but I would recommend keeping your Views and Model separate.
Since our "Model" usually sits in a different assembly our MVC project structure is normally:
Application (all application infastructure code)
Content
css
images
scripts
Controllers
ViewModels
Views
Again this is personal preference but I typically like to keep my static assets (css,images,scripts) under one directory.
You can of course separate things out even further. For example if we're using a javascript plugin that has it's own "core" css and images then we normally keep these together e.g.:
Content
css
images
scripts
libs
myplugin
myplugin.js
myplugin.css
myplugin.png
Of course as you split things out in this way it can become hard to manage. For this reason we use Client Dependency Framework. You could also try Cassette.

ASP.NET MVC 3, Razor Views, and Portable Areas

I am trying to using portable views with ASP.NET MVC 3 and razor views as that seems like the best way to create an easy plug-in architecture. So I have my class library setup and I have my view located in /Views/Admin/Index.cshtml and it is set as an Embedded Resource. I then include that project as a dependency for the main web application project. When I try to access the Admin controller, Index action I get a message that is can't find that view file (so the controller is being properly included). I am assume it is trying to look in the main web application project and not the portable areas binary. Is there a way to get razor views to work with portable areas?
I have been struggling on this particular issue for a while, but I think I finally figured it out.
The folder structure and how the namespaces are called inside your project is very important for this to work properly!
I have a working example of a Portable Area with embedded razor views here:
https://github.com/fretje/MembershipStarterKit
Take a look at the structure of the project.
The area's name is UserAdministration, and there is a UserAdministrationRegistration class in the root of the project, which resides in the UserAdministration namespace.
Then there's a Controllers, Models and Views folder (just like a normal MVC project) and under the Views folder, there's again a UserAdministration folder which contains the views for the area.
Also something else which is very important for the embedded views to work: you have to register a new view engine in the Application_Start method of your global.asax.cs file, did you do that?
PortableAreaRegistration.RegisterEmbeddedViewEngine();
And... In your registration class, make sure you override the RegisterArea method which takes 2 parameters (AreaRegistrationContext context and IApplicationBus bus), and call the base implementation in there:
public override void RegisterArea(AreaRegistrationContext context,
IApplicationBus bus)
{
base.RegisterArea(context, bus); // <== very important!
context.MapRoute(
"UserAdministration",
AreaName + "/{controller}/{action}/{id}",
new { controller = "UserAdministration", action = "Index",
id = UrlParameter.Optional }
);
}
If you don't call the base implementation, you have to at least add a
RegisterAreaEmbeddedResources();
To make sure that your embedded views and resources are registered.
I got this working by following the instructions in Fretje's answer and then also add a nuget package reference to EmbeddedResourceVirtualPathProvider in your website.
Did you make sure that you Marked your View as Embedded Resource in your Portable Area?
Also i found that nice feature of portable areas is that you can override the embedded Views, so if you Place a View in your Host App with Same name and Location of the Embedded one with Different Code Logic it will take priority over the Embedded one Nice !!!
Hope this Helps

Resources