asp.net – 如何添加.aspx页面到现有的MVC 4项目?
我有工作的ASP.NET MVC 4项目.我想添加到这个MVC项目的另一个WebForms项目的.aspx页面.我有几个问题: >我应该在哪里复制这个.aspx文件,我应该如何配置我的 我已经看过links贴在this的问题,但他们似乎已经过时了.很多链接解释了如何添加MVC到WebForms,但我正在寻找所有的方式. 任何有用的链接将不胜感激.谢谢! 解决方法解决方案:事实证明,将.aspx页面添加到现有的MVC项目中,比将.vx添加到.aspx更容易完成任务.对我来说最有趣的是找出在一个项目的范围内,Webforms和MVC都在IIS上共享一个运行时. 所以我做了什么 将另一个项目的.aspx页面添加到我的MVC项目的根目录 public class WebFormController : Controller { } public static class WebFormMVCUtil { public static void RenderPartial( string partialName,object model ) { //get a wrapper for the legacy WebForm context var httpCtx = new HttpContextWrapper( System.Web.HttpContext.Current ); //create a mock route that points to the empty controller var rt = new RouteData(); rt.Values.Add( "controller","WebFormController" ); //create a controller context for the route and http context var ctx = new ControllerContext( new RequestContext( httpCtx,rt ),new WebFormController() ); //find the partial view using the viewengine var view = ViewEngines.Engines.FindPartialView( ctx,partialName ).View; //create a view context and assign the model var vctx = new ViewContext( ctx,view,new ViewDataDictionary { Model = model },new TempDataDictionary() ); //render the partial view view.Render( vctx,System.Web.HttpContext.Current.Response.Output ); } } 将其添加到.aspx页面的codebehind.cs.那么你可以从webforms这样调用它: <% WebFormMVCUtil.RenderPartial( "ViewName",this.GetModel() ); %> >由于我只在所有页面中共享了“菜单”,所以我将其添加到部分视图中,然后在_Layout.chtml中调用它 @Html.Partial("_Menu") 并在MasterPage.Master中这样: <% WebFormMVCUtil.RenderPartial("_Menu",null ); %> 这就是它的一切.因此,我的_Layout.chtml和MasterPage.Master使用相同的共享部分视图.我可以通过浏览它们来访问.aspx页面.如果路由系统有一些问题,可以添加route.IgnoreRoute(“{resource} .aspx / {* pathInfo}”);到App_Start中的routeConfig. 我使用的来源: > Combine asp net mvc with webforms 我希望以后能帮助别人. (编辑:甘南站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |