I'm migrate my old fashion asp.net MVC application to an angular application.
I've created a subset of .html files that contains templates that will provide the HTML code to build my angular components.
Problem
I want to put this html files inside the folder "Views" that already exists on my application. But when I try to access to .html files I receive the following message:
But if I put the .html files outside this folder I can access directly to them:
Questions
Can you tell me why this is happening?
There is anyway that I can access to html files inside the folder "Views"?
To make a long story short, the Views folder is a special folder that holds templates used by actions that are routed by ASP.NET MVC. Because of this, you cannot use it to hold files that are meant to be used directly.
I would suggest ditching the .NET Framework all together since you are going Angular.
If that is not an option or you would like to retain ASP.NET MVC functionality, then simply use another folder (like you have already done by moving the Templates folder to the root).
Try adding an explicit ignore in your RouteConfig
routes.IgnoreRoute("{file}.html");
That should prevent the default routing from taking effect
To make this work, I suggest you take the html markup in your html file and put it on a .cshtml view, that you will render using a GET action in the home controller for instance (as you would normaly do in the MVC pattern).
The other way to achieve this (which I don't recommend), is to add your html file to a deployable folder (like the js folder for javascript files), and than you can call your file using a direct link, however you will lose any capabilities of the MVC pattern this way.
Hope this helps.
As html files are working in views folder, Can you check the path i.e 'Editor/V2/Templates' after 'Views' folder whether it is correct?
Related
I'm unable to get server side includes (*.html files) working in a .net core razor pages web application. I've made sure to have the appropriate handler in my applicationhost.config, but I'm thinking there's a different issue here. Any help is appreciated.
Why am I doing this? I have multiple web applications sharing the server side include files (for navigation bar, footer, head content, etc..). Each of these different applications may be of different Microsoft web architecture. Our goal is to move everything to .net core, but we have lingering web forms projects to deal with along the way.
I have performed a work around by taking the SSI file contents and using #Html.Raw to serve up the content. This is probably wrong also.
I went ahead and changed the file extension of the html files into cshtml which allowed me to treat these files as partial views. I'm using a prebuild event to copy these files from a shared solution folder into my project Pages/Shared/ssi folder. I also copy those partials into wwwroot/ssi for the other applications to use via SSI. Eventually all of the apps will use the partial views instead.
The problem with this solution is that it is not necessarily clear that all edits need to happen in the shared solution folder instead of directly in the project, but the documentation for the project will address this. I tried using linked files, but only one link to a specific file can be made in a project.
Not a perfect solution (to the problem), but this not a perfect website either.
I'm using asp.net mvc 3 and .net framework 4.0 with C#
Let's say I have NivoSlider( a slider ) html code. Also it has js, css and image files.
I want to use the NivoSlider cshtml code and js/css/images as "a project" and I want to add it to different MVC solutions. It will become a plugin some-how.
I can't make it a partialview, because I have to move all the css, js and imges files into new solution. I looked at "mvc areas" but it's not rendering my js and css files ( as a matter of fact; using "Areas" is not a perfect way as you know )... I looked up some plugin based architectures, but none-of-them are easy to implement. I have limited time.
So how can I solve this problem ?
EDIT: I can use this http://razorgenerator.codeplex.com/ - But I'm looking for another solutions if you came up with an idea...
You could create a private Nuget and create a small installation for it. That way you can install, update, and uninstall directly from the package.
You can even make a localized package that you copy between computers. Nuget has a very easy way to specify where you want to extract files to, and what files you want to extract.
I'm using razor generator in a commercial project and it's functional but not ideal.
Other possibilities I considered are Add files as link (see Nameless One's answer)
Also overriding the ViewEngine
Can I specify a custom location to "search for views" in ASP.NET MVC?
Or even symbolic links (shortcut links to folders in windows)
https://superuser.com/questions/234422/does-windows7-support-symbolic-links-folder-shortcuts
As recommended above, Razor views can be embedded into assembly as compiled class (by using Razor Generator).
Static resources as .html, .js, .png can be located in the assemble as embedded resource and served by application via VirtualPathProvider (custom or use existing one like https://github.com/mcintyre321/EmbeddedResourceVirtualPathProvider)
Compile your asp.net mvc Razor views into a seperate dll
I wanted to be able to embed compiled Razor views in a dll. This would allow for easy distribution of asp.net mvc ‘modules’ that have their default views embedded, but allowing you to place files in your ‘views’ folder to override those default views.
http://www.chrisvandesteeg.nl/2010/11/22/embedding-pre-compiled-razor-views-in-your-dll/
I'm trying to load an MVC view form a folder outside the location of the app.
My app is in C:\dev\myproject\ and the view file i'm trying to load is located in D:\viewsfolder\something is it possible to do that?
I tried passing an absolute path to the return View() method but that didn't work.
This is not supported by standard ASP.NET MVC. You may take a look at the RazorEngine plugin which allows you to render a Razor view from a string.
You haven't really explained why you need to do that by the way. Maybe there's a better approach to your particular problem.
The best way to do this is to have your Views Precompiled into a dll which can be used across multiple locations with only one code base.
This can be done using the Razor Generator Plugin which you can find here:
http://razorgenerator.codeplex.com/
How do you add MVC controls to umbraco?
I know in web forms you copy the aspx file into umbraco's usercontrols folder, and the control's dll file into umbraco's bin folder.
But i dont know how to do this for MVC controls.
In solution explorer Go to controller Folder and right click on it then add controller and write the code in it you want
I would recommend reading these to get a handle on how MVC works in Umbraco:
http://shazwazza.com/post/native-mvc-support-in-umbraco-coming-very-soon/
http://umbraco.com/follow-us/blog-archive/2012/10/30/getting-started-with-mvc-in-umbraco-410.aspx
I think you mean one of these two:
1. Child Actions
Read this: http://our.umbraco.org/documentation/reference/Mvc/child-actions
It works in the same way as child actions in Mvc, just that your controllers need to be SurfaceControllers
2. Macro Partials
If what you need is a simple re-usable user controls, then you only need to use partials. You can create a .cshtml file inside Views/MacroPartials then create login to /umbraco and create a Macro that references that partial.
You can the render it with #Umbraco.RenderMacro("myMacro")
My objective is to write a program that can create folders and within those folders create Default.aspx pages. The Default.aspx pages must read information from the database to populate the page using their containing folder name as a parameter to call the database.
Create the folders is the easy part, but I'm not sure how to go about writing information to .aspx files.
The goal of this project is so a real estate company can create pages for featured properties (through a cms), each featured property getting it's own folder/page.
Any feedback would be great.
-Aaron
Rather than physically creating the .aspx files, I think it makes more sense to have 1 .aspx file, which is passed querystring values to return different content from the CMS, depending on its value.
Furthermore, you could use URL Rewriting to make the file appear as if its in a physical location, within a folder.
For example:
/Property.aspx?agent=EstateAgent1&name=Property1
Can be rewritten to:
/EstateAgent/Property1.aspx
If you have to generate folders and files, I'd recommend simply generating HTML files, as theres no need for the file to be dynamic, or ran at the server
I would create a template ASPX page, and copy that template into the new folders. Within the template, define the layout and add all of the necessary controls for displaying the data. Doing it this way, you can change your template as needed for changes, and after the template is copied to the folder you can customize it as needed.
I would be remiss not to warn you that this approach will be very difficult to maintain though. Unless there is some requirement I'm unaware of, I don't know why this approach would be favorable.
Hope this helps.