Asp.net MVC3 working on razor as well aspx view engine in parallel - asp.net-mvc

I wanted to convert my views from aspx view engine to razor as we moving forward with new version of MVC, but it is hard to convert everything in single stretch as it is really huge,
is it possible to do it in parallel.
I mean does MVC allows to have few razor views as well as well aspx views and run with out any issues?, or what would be the work around?
Thanks in advance

Yes, the MVC does allow you to mix ASPX views and Razor views on one project.
The framework is very flexible. I've been involved with a couple sites using both aspx and Razorviews. The reason was ALWAYS that they were moving from one to another.
In these cases the aspx pages were not mass changed. New pages were universally Razor and aspx pages were only converted when serious work or re-work was already being done to them.
Followup
there are many aspx to Razor converters. I don't recommend this approach but be aware this is Microsoft's app for convertion.
http://visualstudiogallery.msdn.microsoft.com/d2bfd1ca-9808-417c-b963-eb1ea4896790

Have you tried http://razorconverter.codeplex.com/ ?
It looks promising.
It had some issues with included controls a time ago, but I'm not to updated.

Related

Embedding an MVC form inside the old master template architecture

I have an old Umbraco web application which was upgraded to v6 earlier this year.
It uses .NET ascx user controls and your standard .master pages as you'd expect.
I now need to create a brand new page which is essentially a booking form for an event.
I'd like to create it using MVC, as I do everything with MVC nowadays. I don't really want to duplicate the page layout / the frame. Is it possible to embed an MVC partial view inside the old master templates?
You can create the form in a .cshtml file and then add it as an Umbraco Macro. But the form couldn't use the MVC approach, it would have to be basic inline razor plus conditional statements. Which is fine but limiting. You could of course have the form posting to a controller action too but this get's a little tricky as it takes the form processing out of the page's event cycle.
Otherwise you are asking if you can reference an action in a masterpage, so no not really. I say "not really" because of course you can but it's unnatural and would make the project a nightmare for anyone to undestand of they were to pick it up. There is an article here as to how you might do it tho': http://www.hanselman.com/blog/MixingRazorViewsAndWebFormsMasterPagesWithASPNETMVC3.aspx
Also, there is also the Umbraco MvcBridge package. This was something a lot of devs used prior to being able to build directly in MVC. Essentially you can set up Macros to point to actions etc. but still within the webforms mode.
It's a great half-way house but I'm not sure abut the compatibility with v6.

Can MVC framework be used in a web application that is currently using ASP .NET?

I recently joined a group that manages a Classic ASP web application. It has been working fine for our group's need. However, a decision was made, before I joined, to move to ASP .Net. Since we are mostly ASP developers, we write code in ASP .Net as we would in Classic ASP (for the most part). Would it be possible to introduce MVC to this application/project?
Thanks!
Yes, it is possible to use MVC in a traditional WebForms project. I migrated a large WebForms project to MVC 2 a couple of years ago, and here are my findings (I have updated them to reflect MVC 3)
Make sure you have .NET 4.0 installed, as well as the MVC 3 framework and VS extensions.
Create a new blank MVC project to use as a reference.
Look at the default web.config for the reference project. You basically want to use the reference web.config, and merge in stuff you need from your current project.
Look at the reference global.asax.cs. Similar to the above, you want to merge the changes in the reference .cs into your current application's global.asax.cs.
You will need to add the following references to your web project:
System.Web.Abstractions,
System.Web.Extensions,
System.Web.Helpers,
System.Web.Mvc,
System.Web.Routing
You can enable the VS extensions by changing the ProjectTypeGuids:
In Solution Explorer, right-click the project name and select Unload Project. Then right-click the project name again and select Edit ProjectName.csproj.
Locate the ProjectTypeGuids element and add {E53F8FEA-EAE0-44A6-8774-FFD645390401}.
Save the changes, right-click the project, and then select Reload Project.
Add the following standard folders for MVC content:
~/Views
~/Views/Shared
~/Controllers
~/Models (for your view models, optional)
~/Content (for CSS and images, optional)
~/Scripts (for JS, optional)
Additional notes:
If your existing WebForms relies on web.config settings for authorization (such as preventing unauthorized users), this won't be recognized by MVC actions, because routing works completely separately from the WebForms authorization. Use AuthorizeAttribute to require authorization, or constrain actions to certain roles or users. You can even specify global filters so you don't have to apply this attribute on every single controller or action.
There may be additional considerations for making MVC work with IIS versions prior to 7, or with application pools that use the Classic pipeline. Consider using IIS 7+ with Integrated pipeline.
My notes above mainly involve getting the baseline of MVC working, which uses ASPX views. ASPX views use the same markup as the ASPX files you are used to in WebForms. You can also use the new Razor syntax (primer), which I highly recommend. You can use both ASPX and Razor view pages at the same time. However, you cannot use an ASPX master page on a Razor view (or vice versa). Also, MVC will find and use ASPX views before Razor views, so if you upgrade a view to Razor, delete the original ASPX. You will need to do a little additional work to enable Razor views. I'm trying to find my notes for enabling Razor. I'll update when I find them. Once you do have Razor installed and working, you can use this tool by Telerik to convert ASPX to Razor.
Here is a question on SO about a problem I'd had while upgrading. I'm only providing it because it covered some of the points I mentioned above in more detail. However, I was upgrading to MVC 2 at the time, so some of this stuff is out of date.
The short answer is yes it is possible.
Scott Hanselman has written about this topic before.
Depending on the skills in your team, you may well find it difficult to get up to speed - it is possible to write clean MVC style code in Classic ASP but most people don't.
It is of course technically possible. However, it sounds like it would be a cultural shock, as MVC works quite a bit differently than Classic ASP or ASP.NET WebForms. I think it would be worthwhile to do - or just stick with ASP.NET WebForms if that seems more natural. But if you've not yet fully committed to WebForms, MVC seems just as easy to move to, IMO.
Yes. I worked on a project that began as plain ASP.NET and later added some ASP.NET MVC pages. Eventually we liked MVC so much more that we eventually migrated all of our WebForms pages to use MVC instead. But the whole time, the two systems worked very well together.
Here's the only real gotcha that I can remember running into: WebForms works by having the entire page encased in a big <form> tag. Since HTML doesn't allow you to have nested <form> tags, you typically can't use MVC forms inside of a WebForms page. Either keep your WebForms pages separate from your MVC content, avoid using HTML forms in MVC content that may appear on a WebForms page, or use popup dialogs for your forms that get created outside of the WebForms DOM area.

Does MVCContrib support MVC4?

Does MVCContrib support MVC4? I am trying to use it in my project. Can any one help me with an example?
Does MVCContrib support MVC4?
No.
The documentation mentions support for the script and style bundling of MVC4. Other discussions on codeplex indicate that T4MVC in MVC4 is working for people.
https://t4mvc.codeplex.com/documentation
Support for MVC's script and style bundles
Starting from MVC4, one can define "bundles" of scripts and
stylesheets which are automatically combined and minified. However,
magic strings are used to define the resource URLs. To eliminate them,
follow steps 1 to 3 below.
It appears full support for this is still being added. But the features that worked in MVC2 I know still worked in MVC3 because I used them in MVC3; but the documentation does not explicitly say it works with MVC3. I suspect that every feature in MVC4 that was part of MVC3 still works in MVC4.
Here is the reference discussion for bundling:
http://t4mvc.codeplex.com/discussions/399205
T4MVC is still better than relying on magic strings to reference controller actions and view names. In my opinion the next version of MVC just needs to include T4MVC in the base feature set. Until that happens I'll continue to use T4MVC.

How can I make ASP.NET MVC 3 use views (aspx, ascx) files from an external assembly in my website?

I have an ASP.NET MVC 3 website and I'm looking for a way to package up a set of views and controllers into an external DLL and hopefully use MEF (Dependency Injection) to load the correct controllers and views.
Does anyone know if something like this is possible and any good links to tutorials on the subject?
Precompiled Razor for Shared Views and Mono
Compile your asp.net mvc Razor views into a seperate dll
A combination of those two will probably get the best result in your case - My precompilation code handles some things the single file generator doesn't, but Chris has more use of out of box code at runtime, which is probably better if you only need to run in a standard mvc3 setup.
I have also used aspx files set up as embedded resources ( Views in separate assemblies in ASP.NET MVC ), but Razor is quite a bit easier to work with in compiled form.

Upgrading ASP.NET MVC2 project to MVC3 and using mixed View Engines

Can I upgrade my MVC2 project to MVC3 and continue to use my ASPX views, AND at the same time start writing some new views in Razor?
More specifically, Can I take an ASPX view page, and a Razor control in it? Would such a thing be possible?
Any other things one should look out for?
You can definitely mix view engines across totally separate views. As for putting Razor "controls" in an ASPX page, if you use RenderPartial, it should work.
One thing I would watch out for is that if you use Master Pages then you may end up duplicating them for both view engines. I had a good ol' WebForms Master Page, used by all my regular .aspx content files, but creating a new view using Razor means I have to use a duplicate Razor layout page alongside that old Master Page.
I haven't looked into it too much, but at first try I get 'The file "~/Views/Shared/Site.Master" could not be rendered, because it does not exist or is not a valid page.' and certainly there's nothing in Scott Gu's blog entry introducing Razor to suggest you can combine them, but I could be all wrong here.
http://www.hanselman.com/blog/MixingRazorViewsAndWebFormsMasterPagesWithASPNETMVC3.aspx
For how to mix view engine master pages...

Resources