MVC empty WebSite project based on aspx pages - asp.net-mvc

In Visual Studio we have a two ways that create the web projects.
I create the "WebSite" project, empty-project (like: File -> New -> WebSite... and so on).
After that, when the WebSite created I want to make it to MVC WebSite with ASPX, and not Razor pages.
[I decide create the MVC WebSite not Project Site, with this way, because the Visual Studio doesn't provide us WebSite with MVC template based aspx pages].
After creating some pages I want to create and integrate any Razor page.
Describe for question:
IF I attempt use in the Razor view page - " #model MyWebSite " it does not discovering, and I can't use with the ViewBag property later
Question:
What Can I do ?
What NuGet packeg I need install or what dll recourse I need adding to Bin folder of project.

Yes, you can use Razor with an existing ASP.NET WebSite. Simply open your website using the WebMatrix tool and start adding CSHTML files. One caveat is that if your website is using WebForms controls the WebMatrix tool will not provide any help working with them in existing aspx pages. Additionally, Razor does not support WebForms so you will not be able to add something like to a CSHTML file.

Related

In MVC what extension should the view file names have?

I have been given a sample MVC project that contains views with extension .aspx
however when I create a new MVC project using the VS2013 ASP.Net wizard the views have extension .cshtml
Are there 2 kinds of MVC project?
Views in MVC refer to either .cshtml files in C# or .vbhtml files in Visual Basic.
.aspx files are webform files and are not views-- this was the initial approach ASP.NET took to make webform development more similar to desktop application development. These pages are generally included in the route list as actual files, whereas MVC uses controller routes that aren't based on existing files (i.e., the url path doesn't match the file and directory structure like traditional html does), which ultimately serve the views. .aspx files can also have code-behind files to separate the html/aspx markup from the .NET code; those files will have either a .aspx.cs or .aspx.vb extension on them. In an MVC app, these files are also likely to have designer files.
One set of files for an aspx file named MyPage may have the following files:
MyPage.aspx
MyPage.aspx.cs or MyPage.aspx.vb
MyPage.aspx.designer.cs or MyPage.aspx.designer.vb
The files in #3 may be hidden until you select 'show all files' in the project, or may not exist at all in a traditional 'web site' project type. I think you have to upgrade to a 'web application project (Wap)' project type before you can integrate MVC, though I may be wrong. All WAP projects should have these .aspx.designer.xx files.
In MVC what extension should the view file names have?
.cshtml unless you have a reason not to use the Razor view engine with C#.
Are there 2 kinds of MVC project?
The relevant answer is that there are many more than 2 different view engines. Razor was introduce in 2010. The Razor view engine is what comes out of the box in the Visual Studio MVC templates. See ASP.NET MVC View Engine Comparison for more info on more obscure view engines that work with ASP.NET MVC.

DevExpress ASP.NET - Want to use Razor without MVC

I test the DevExpress (DX) ASP.NET
I want to make website with DX and Razor view.
When I create a new Web Project. I can choose between :
DXperience v12.2 ASP.NET Web Application
DXperience v12.2 ASP.NET MVC Web Application
In the choice 1, I can't choose the view language, Visual Studio create an ASPX website.
If I choose MVC, in the creation wizard, I can choose Razor or ASPX.
My question is can I create a website using Razor view without the MVC ?
I don't know the MVC pattern and be affraid to learn it now, I don't understand the logic inside it...
Depending on what you are specifically looking to do, you should check out RazorEngine - it lets you render HTML from Razor without alot of the scaffolding that you will have to do in order to use Razor like MVC uses Razor...

How to open MVC 4 view page from webform.aspx page?

basically i am looking for something like this ,
i got webform.aspx page and have button there, if i click on it i need to show MVC view page
idea is i want app with webform and mvc !
what i am trying is :
http://www.packtpub.com/article/mixing-asp.net-webforms-and-asp.net-mvc
but here i am confused about webconfig settings
please help me to get it done,
thanks
Scott Hanselman has a good guide on integrating MVC with a Web Form App, it should take you through the steps, here it is in a nutshell:
Run the Upgrade Wizard (open the Visual Studio2008 Web Application
in Visual Studio 2010)
Create a default ASP.NET MVC application for reference (you'll throw it away later)
Use a differencing tool like Beyond Compare to integrate the new web.config entries from the ASP.NET MVC sections into the upgraded ASP.NET WebForms application

Side-by-Side Asp.Net and MVC Razor

We have an existing ASP.Net Web Application. I would like to create an ASP.Net MVC Razor Application where the two applications will work together. A single Master Page would contain menu items that can call .aspx pages as well as Razor .cshtml pages.
I have seen an example using MvcContrib Portable areas utilizing Routing. This particular example has .aspx pages in both (the MVC was not Razor).
Is there an example out there that will show the two running side-by-side and the MVC is Razor? It would be best if I could download a visual Studio Solution so that I can run this.
I am not sure if the MvcContrib way is the latest and best way to achieve this.
I do not want to go Hybrid!
You don't need any other external librarry. You can always convert the existing ASP.NET web forms Project to be a Hybrid one which uses webforms and MVC. You need to add the required MVC assembly references and make some changes to the web.config and you are all set. Scott has a simple and awesome blog post about this where he explains how to do the conversion.
I scribbled a note about how to enable the MVC specific Context menu( Add Controller / Add View) in the hybrid project after conversion here

ASP.NET MVC - Missing "Convert to Web Application" option

I created a new MVC project and added some webforms pages to it in an effort to start adding new pages to my app using MVC and eventually port the old pages over as well. Everything is building and working correctly but I did notice that I don't have the "Convert to Web Application" option when right clicking an aspx file. And I think its not regenerating my designer files when I change the controls on a page.
My guess is that the ProjectTypeGuid is wrong or in the wrong order. Can someone confirm?
Old (Webforms) project file
<ProjectGuid>{4F95C3D9-228E-4BD5-9840-46224BA3EBA7}</ProjectGuid>
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
New (MVC) project file
<ProjectGuid>{A4690D3F-695B-4BF4-93B7-EA5B17793051}</ProjectGuid>
<ProjectTypeGuids>{603c0e0b-db56-11dc-be95-000d561079b0};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
This is so wrong on so many levels but I am going to answer you anyways in the hopes I might get an uptick or something. You have two routes with this. First route which I use all the time is put your mvc applications in their own projects. When your deploying the site drop the webforms application first, and then make a folder in that webforms application and put your mvc application into that folder. That should work like a charm for you. If you insit on having webforms and MVC Framework in the same project, then don't drop your webforms into the view folder. Create its own folder because you can not directly access your aspx pages from the views folder without making modifications to the web.config. Hope this helps.
MVC is available as a Web Project only. The VS2005 style Web Site is not supported.

Resources