In WinForm and WebForm Application, Visual studio groups the 'View' File and 'Contorller' File, together. I found very easy to manage file in that way.
Now in ASP.Net Mvc , i'm finding difficult to manage views, separately in completely different folder.
Is there any way to group View and Controller files in VS Solution Explorer, like we used to do in WinForm and WebForm Application ?
I think they did that on purpose - views should be independent from controllers. Think of it like this: you should be able to put controllers into a totally different assembly and still have your application work. Your controllers should also be able to work with totally different set of views.
The framework is also setup to go to the views folder to fetch appropriate files. You would have to change that behavior yourself if you decide to move the views. Might not be worth the hassle.
And finally, if you really want to do it, you should probably look at your project file. There is a DependsUpon element that you can use to make a file go underneath another:
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
you can use VSCommands to group/ungroup files directly from Visual Studio
Related
I have two environments that use Umbraco: Live and Dev.
As I have in research, Umbraco will be create a physical file when a user creates a new partial view, macro, etc. so, I have two questions:
1. What is the best way to know which files were created on Live and how to migrate them to Dev environment for the purpose of creating new features?
I have tried to Google and found "Hybrid Framework" but it is not up to date and I want to maintain code by myself.
2. I want to extend Umbraco with my own code. What is the best practice for this? (I do not want to change any code in the original Umbraco Source, just create my own new code)
As I know, I can create a package for extending code but I just want to know the other ways.
Partial Views, Macros , Templates are .cshtml files, these will not affect your source code. Same is case with css and js files; these will not harm any source code.
Just copy paste these files in respective folders and reload the nodes in backend. It will work properly.
Other way is you can create a package zip file from developer section where you can export datatypes, content and files, and install it in other environment.
This question has probably been asked before but my search failed to turn anything up. Is there an easy way to find out whether a view/partial is not being used in an MVC project? Currently I'm searching for the individual view name across the entire solution but wondering whether there's a tool out there that would make this job easier? I'm ideally looking for something that would provide a visual indication within Visual Studio if a view/partial is not being used.
I'm basically cleaning up an existing codebase and want to rip out any views that are not being used any more.
When I want to see if a view is used, I move it out of my project and enable view compilation. If a view is referenced from somewhere else it usually breaks.
enable view compilation by manually editing your mvc csproj file and setting the following
<PropertyGroup>
<MvcBuildViews>true</MvcBuildViews>
</PropertyGroup>
I have a visual studio solution with multiple telerik MVC4 razor projects having same look and feel. I don't want to have same layout, CSS/styles, images and js files copied in all MVC4 projects. What is the best way to accomplish this re-usability? I tried creating a virtual directory of a commonUI project and tried to refer _layout.cshtml using http://localhost/... in _ViewStart.cshtml but it complained saying "http:/localhost/MyMvcApp/Views/Shared/_Layout.cshtml' is not a valid virtual path."
Please help!
Four recommendations:
1) Look into areas, maybe instead of having separate projects these are really different components of the same system (admin, etc.)?
2) Use add existing item in visual studio and add the items via links. This still duplicates them for deployment, but you can keep one source.
3) Consider doing this by building your own nuget package. That way although you would copy the CSS and images you would have it packaged up and could update the package as needed. The benefit is that you can update one project while not having to re-test the other (if they are separate and 1) doesn't apply).
4) I find this one uglier than the rest, but in IIS I believe you can map in folders, so you could refer to these files by links in your project, not deploy them there and then map in the appropriate folder at deployment time using a single source path.
I know of no way to share up the application path.
EDIT:
I have never tried this before, so can't vouch for it working, but maybe compile your shared items in a separate project and then reference the DLL in all other projects.
The reference I found is this, but again, I haven't confirmed that this works, just think this could be a viable path to explore:
http://www.chrisvandesteeg.nl/2010/11/22/embedding-pre-compiled-razor-views-in-your-dll/
Areas are bad because you cannot deploy them separately. Like you, I tried using virtual directories, and was successful referring to the layouts using relative syntax:
#{
Layout = "~/Common/Layouts/Layout-001.cshtml";
}
Above, the project's layout inherits the layout in the /common/ virtual directory at the root. As the common layout (along with it's bootstrap & jquery versions) evolve, you can use side-by-side version-named physical folders (like common.v01, common.v02,). So you can upgrade your applications to a newer common layout by changing the VD's path to the appropriate version.
The downside with this is you'll need to use IIS (not express) as your dev and test platform.
We are currently using the default folder structure for our MVC app, and were wondering if it is possible to instead put a Controller and its related views into the same folder.
For example, a subset of our current structure is:
Model folder
OrderViewModel.cs
Views folder
OrderView.aspx
OrderGrid.ascx
OrderHeader.ascx
Controllers folder
OrderController.cs
Desired:
Order folder
OrderController.cs
OrderGrid.ascx
OrderHeader.ascx
OrderViewModel.cs
OrderView.aspx
We have hundreds of actions/views, and they're currently grouped into too few controllers. This is partly because it becomes a pain to navigate around the project when flipping back and forth between a view and its related classes. The above solution would allow a developer focusing on one controller action to have all of them easily accessible.
I guess Areas could help with this too, but we'd have to make ~100 areas (one per set of closely related screens) to make this useful from my team's POV.
The default controller factory uses reflection to find all classes that derive from Controller, so no matter in which folder you put them, as long as they are public and derive from Controller it will work. But IMHO mixing views and controllers into the same folder is not a good idea. If it is a matter of organizing your controllers why not create subfolders in the Controllers folder?
I'm not sure that diverging from convention is a good idea, as people are probably used to the standard folder layout - but I do feel your pain.
Navigation between files would be less painful if Visual Studio had some more of the features found in IntelliJ IDEA.
The fact is, pretty much any folder structure will degrade over time, as more files are added to the project, and better tools are usually a more efficient solution to the problem.
To be fair, it looks like VS2010 is starting to take some of the IntelliJ ideas on board, so things will probably improve - but there's a long way to go before Microsoft catch up.
EDIT: I forgot to mention that there is a plugin that provides lots more functionality for Visual Studio - pretty much bringing it up to the same level as IntelliJ
I'm creating a solution where I have several projects, each of them having the responsibility of dealing with entities, MVC views and controllers of a certain kind. That is, one deals with accountance, another with company management, etc. This allows us to reuse them in multiple solutions.
I'm able to use the views in the different assemblies from the core project of the solution (a standard MVC project) by registering a VirtualPathProvider, and the trick of making the views as Embedded Resources, so they can be loaded from outside their DLL.
The main (and huge) drawback of this approach is that by setting the views as Embedded Resources takes away the possibility of compiling, using IntelliSense and debugging them, so it makes the development really tricky, and the maintenance even more so.
Is there any way to make compile this views inside DLLs? Am I missing something there or is there any other better approach to this?
Note: I can compile views in my MVC Project, but not the ones inside the DLLs.
I don't know if this helps you, but...
For a while I wanted to do the same as you until something occurred to me: As long as the views exist as .aspx and .ascx files, they can be used to 'skin' the application since they are not part of the compiled application. In other words, the benefits from having all the Views as uncompiled files in the final, composed application are just too great to ignore, IMO.
So I ended up deciding that the final, composed application is responsible for how everything is rendered. That also means that if I have two different applications that reuse the same modules, they can render these very differently.
These files should contain only rendering code anyway, so should really be developed by a HTML/Graphics designer - not a developer.
All Controllers and ViewModels I still implement in separate modules (.dlls).