How do I run my mvc 2 web application using the code-behind classes rather than the generated dll it creates when compiling ?
The reason for this is so I can update an Action in a controller for example via the .cs file rather than having to redeploy a new dll for the whole site.
Similar to how you could have websites in asp.net 2 webforms rather than web applications
ASP.NET MVC uses ASP.NET application instead of ASP.NET website so what you are asking is not possible. The application needs to be precompiled before deployment.
Now this being said you could in fact you a web site as model for ASP.NET MVC application but be prepared to do everything manually.
Create a new ASP.NET website
In the special App_Code folder add a controller
Add the Views folder containing the corresponding web.config, layout and views
Configure your routes in Global.asax
So you need to put all your code behind (controllers, models, ...) in the special App_Code folder.
Related
I am new to .NET Core and I still trying to get all puzzles together.
One strange thing for me is.
I am using VS2015 CE Update3
When I create new project under
Visual C# -> Web -> ASP.NET Core Web Application
And on next form when I Change Authentication to Individual User Accounts
In my project under Solution Explorer explorer there is context menu on folder Controllers with give me ability to create new Controller using Entity Framework
If I create same project without changing authentication mode.
I do not get ability to create MVC Conntolers using Entity Framework?
Why ?
What I am missing in project whitout autentification to be able to create Scaffold Conntolers and Views
Even if I install Entity Framework using NuGet according to ASP.NET Core Docs for Enitity Framework I still do not get ability to Scarfold MVC Conntolers
My apologies for spamming here on SO.
If I did not asked I will not ever find solution
Looks like this is know issue for .NET Core Preview 2 Visual Studio tooling
There is note on next docs which I did not not reach because I stacked on line bofore
Don't miss setting authentication to Individual User Accounts. You
won't be using authentication in this tutorial, but you need to enable
it because of a limitation of .NET Core Preview 2 Visual Studio
tooling. Scaffolding for MVC controllers and views only works when
Individual User Accounts authentication is enabled.
Is it possible to declare functions (as you would do in C# not javascript) or create classes in ASP.NET Web Pages?
How about in MVC, in the View files?
If not, is there anyway to do event handling in Web Pages? (Again, NOT javascript eventhandling)
You can create your own functions within .cshtml files. This article explains the functions keyword and how to use it: http://www.mikesdotnetting.com/Article/173/The-Difference-Between-#Helpers-and-#Functions-In-WebMatrix. If you include it in the .cshtml file that also makes use of the function, you cannot call it from other pages. If you wanted to do that, you can add a function to a .cshtml file and then put that in App_Code.
There are no events as such in ASP.NET Web Pages. You can check to see if a page has been posted back using the IsPost property.
If you want to make use of reusable utility methods in MVC, you are better off taking the more traditional approach of creating static classes and adding your methods there. App_Code is really for Web Site projects (ASP.NET Web Pages) as opposed to Web Application projects (whcih is what MVC apps are).
I have an MVC web app, and a nested admin application with areas with the same name:
/localhost/videos
/localhost/admin/videos
These are separate projects in the VS solution. The admin project is deployed into a folder off of the root app
Both Videos areas have a controller called VideosController. It appears that MVC is calling the root application's VideosController.Index instead of the admin site's VideosController.Index, but is (correctly) trying to return the admin/areas/videos/views/videos/index view.
I'd rather not have to go in and rename all of the admin controllers. Any suggestions?
What might help is specifying the default namespace.
typically something like this:
ControllerBuilder.Current.DefaultNamespaces.Add("MyProduct.Controllers");
So now, if MVC has two of something, it will have a default to fall back on. You will see a lot of the same issues if you start using Areas.
I'd like to develope simple set of controls to display many sort of data and be useful in normal silverlight application and can be used in ASP.NET MVC2 application. Right now i have no idea how to link those tehnologies, but this isn't my concern right now - i just heard it is possible and i'll find out how to do that...
Right now i'd like to know how can i use my Model's classes in such SIlverlight class library. I've generated POCO classes in EF4.0 for ASP.NET MVC2 application. Everything works great, but now i'd like to use some of those classes - create silverlight's controls, some ViewModel classes and fill my controls with data passed from my Model, used in ASP.MVC's app, through ViewModel.
Everything should be tested in any simple silverlight's app and at the end i'd like to be able use this class library in silverlight app and in ASP.MVC 2 website...
Silverlight it's own runtime and in general you cannot mix normal .NET assemblies and Silverlight assemblies.
However, one option is to share the source code by linking the same source file to two projects that compile to the different runtimes.
Another option is to use WCF RIA Services where Visual Studio will code generate your model classes in the Silverlight project and there are also options for sharing code between tiers. You will also get a service to operate on the objects from Silverlight. The service can be built on top of EF4.0 with very little code.
Finally, Silverlight 4 and .NET 4 are in some cases able to share assemblies if certain criteria are met. See Stack Overflow question named Silverlight 4 Assembly Sharing Problem.
What you need to do is use shared code.
you do this by adding an existing file to a project. In the add file dialog there is a arrow on the button that exposes the add as link option.
the point of this is that you cna have 2 projects which target the different CLR's but contain the same code and namespace references ... you can leverage these to have code that works on both versions of the CLR very simply.
Its really quite powerful. I have one set of tests that can target both versions.
Of course you are limited to the set of common functionality but that is implicitly part of your requirements anyway.
You cna even pass the objects over a service and have them deserialise nicley into the other CLR. Kinda suprising how well you can use the symetry
I am currently using this for aproject and am achieving what you want and after a few hours of playing with really suprisingly painless.
regards
I have converted my ASP.NET web forms project into an MVC project by adding the MVC ProjectType guid in the project file. All of my MVC 2 project items are showing up (View, Controller etc.) but for Areas. I have MVC 2 installed so I'm not sure what's not setup right.
Turns out that an MVC 2 project has a different GUID which makes sense since they are supposed to work side-by-side. I ended up using {F85E285D-A4E0-4152-9332-AB1D724D3325} .
P.S: You have to add this at the start of the element like this:
< ProjectTypeGuids >{F85E285D-A4E0-4152-9332-AB1D724D3325};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}< /ProjectTypeGuids >
It wouldn't load when I added it at the end (as described in Sanderson's book).