I've been searching how to add webforms to MVC project but there lots of sites explaining only how to add MVC to an existing webforms project.
Is there a way to do that ? Maybe need to add some code at Web.Config ?
The .aspx.cs can't find any control on the .aspx webpage, that's the trouble !
Thanks!
You can add a WebForm to your MVC project and have it work. You can also add WebForm controls to an MVC view as long as you have a <form runat="server"> around it.
It irks me to post this ... but I went Add New Item ... and added an Ajax Web Form into an MVC 2 project and the code behind was added and linked to the web form.
Related
I have two projects (one ASP.NET MVC and one ASP.NET Webform). I am showing the aspx page of webform project in one panel of the cshtml page of MVC project.
I wanted to pass a value from the action method of controller to the aspx page and I need to use it in the webform project. Could some one help how to achieve this?
Thanks in advance!
I have created a new ASP.Net 5 application as empty and tried to add the aspx page through add new item. but there is no options to add aspx page rather that we can have all other items like view, controller, class library.
Any suggestion is greatly appreciated.
Thanks in advance.
Files ending in .aspx are part of the Web Forms framework. ASP.NET 5 does not support Web Forms at all, nor will it ever support Web Forms. If you want to create a Web Forms application using Visual Studio 2015, you should choose Web Forms from the ASP.NET 4.6 Templates instead.
ASP.Net 5 is like ASP.Net MVC, you cannot add .aspx page but .cshtml razor view into your Views folder.
ASP.NET 5 support both MVC and webfrom. We have choose web application templet with Web Form, MVC or API.
https://docs.asp.net/en/latest/tutorials/your-first-aspnet-application.html
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
can anybody tell me that if i made a normal asp.net c# project and in that solution i want to add mvc project. so is it possible to call mvc view from normal page which is in first project? if yes then how can i call view page from normal page of asp.net c# project.
on live server how can i call mvc page?
Thanks
Samir
Mixing VB ASP.NET and C# ASP.MVC projects in a single solution
Ok, couple of different things here.
Can a ASP.NET forms project exist in the same solution? Yes
Can you mix MVC with WebForms in the same project? No
Can a MVC site communicate with a WebForms site? Yes, you can easily pass between via simulated form submission or by URL. You could also configure cookies to work across both sites.
Can you have an MVC site and a WebForms site use the same url? No
I am adding MVC to a project that has MANY legacy webform pages. This works fine. However, I currently have a separate masterpage for MVC and for the webforms. The two master pages produce essentially identical output. I'd really like to kill the webforms one and just use the MVC master page with all my pages and stay DRY.
Not being DRY has already bitten me a couple times when I forgot to change both.
I tried doing the obvious way and just pointing the webform content page's MasterPage attribute at the MVC masterpage. This throws an error saying the MVC masters only work with MVC views.
This seems like it would be a pretty common problem with mixed MVC and webform projects. My MVC master isn't doing anything with ViewData, so I don't see any reason the webforms couldn't use them.
You can absolutely share the same master page. Your MVC master page must simply point to the WebForms masterpage via its MasterPageFile attribute. This applies your WebForms MasterPage styles to your MVC MasterPage.
I am using this setup in production.
The declaration on my MVC Master Page, pointing at the Web Forms Master Page:
<%# Master Language="C#" MasterPageFile="~/MasterPage/Site.Master"
AutoEventWireup="true" Inherits="System.Web.Mvc.ViewMasterPage" %>
Works like a charm.
This blog post walks you through the necessary steps to share WebForm and MVC master pages with little or no duplication. It also includes a sample project you can download, and I found it quite helpful.
One hiccup I ran into was that I was using a LoginStatus control in my header. LoginStatus must be inside a form so I couldn't use it in my root master page (not wanting to end up with nested forms on all my MVC pages). But that was a pretty easy control to replace with a simple code block in my root master page.
In my webforms app, my master page inherits from "HLPUSD.SMART.SMARTMaster" which is just the namespace for our application and then the name of the webform class.
In my MVC project, the master page inherits from "System.Web.Mvc.ViewMasterPage"
Me thinks this has something to do with it?