在MVC3 aspx页面 [英] Aspx page in MVC3

查看:107
本文介绍了在MVC3 aspx页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发使用Visual Studio 2010的应用程序MVC3

I am developing an MVC3 application using Visual Studio 2010.

我有我想要显示的控制器操作的结果的aspx页面。

I have an aspx page that I want to display as a result of a controller action.

我添加了这个动作的家居控制器。

I added this action to the home controller.

// GET: /Home/EmployeePortal
        public ActionResult EmployeePortal()
        {
            return View();
        }

这是aspx页面。

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<!DOCTYPE html>

<html>
<head runat="server">
    <title>EmployeePortal</title>
</head>
<body>
     <asp:TextBox ID="TextBox1" runat="server" />
    <div>
        This is employee portal
    </div>
</body>
</html>

当我运行应用程序,我可以使用url导航到该页面:
的http://本地主机:3990 /主页/ EmployeePortal

When I run the application, I am able to navigate to this page by using the url: http://localhost:3990/Home/EmployeePortal

问题是 - 当我有aspx页面上的一个或多个服务器端控制,我得到的网站上此错误。
很抱歉,在执行您的要求时发生了一个错误。

The problem is - When I have one or more server side control on the aspx page, I get this error on the website. Sorry, an error occurred while processing your request.

当我从页面注释掉在服务器端控制,它显示的罚款。

When I comment out the server side control from the page, it displays fine.

aspx页面添加作为视图通过添加新的视图菜单中的应用程序。

The aspx page was added as a view to the application via add new view menu.

我需要融入MVC应用程序的aspx页面和这就是为什么我试图用这个aspx页面。

I need an aspx page integrated into the MVC application and thats why I am trying to use this aspx page.

我不知道我做错了。请帮忙。

I am not sure what I am doing wrong. Please help.

推荐答案

您不要使用服务器端控件在ASP.net MVC。

You don't use server side controls in ASP.net MVC.

您使用HTML辅助方法:

You use the HTML Helper methods:

<%= Html.TextBox("TextBox1") %>

服务器端控件不MVC支持,因为MVC不具备的ViewState的概念。

The server-side controls are not supported in MVC because MVC does not have the concept of ViewState.

编辑:

如果您需要整合MVC和WebForms的,那么你需要创建独立的Web窗体页。这些将不会在你的MVC应用程序视图。然后,您可以通过执行以下操作在Global.asax中创建路线这些Web表单页面:

If you need to integrate MVC and WebForms, then you will need to create standalone Web Form pages. These will not be "Views" in your MVC application. You can then create routes to these web form pages by doing the following in your Global.asax:

public static void RegisterRoutes(RouteCollection routes) {
    routes.MapPageRoute(
        "WebFormProducts",
        "/products/{category}",
        "~/WebForms/Products.aspx"
    );
}

现在,当你去/产品/饮料它实际上会去那住在WebForms的文件夹Products.aspx网页。

Now when you go to /products/beverages it will actually go to your Products.aspx page that lives in the WebForms folder.

您创建这个Products.aspx文件一样正常web表单页面。这个缺点(如果一切都没有改变)是您不能共享一个母版页/布局页,所以你必须复制任何布局,并创建一个名为.master,使页面看起来很相似。

You create this Products.aspx file the same as a normal webforms page. The disadvantage to this (if nothing has changed) is you can not share a Master page / Layout page so you will have to duplicate any layout and create a .master to make the pages look similar.

这篇关于在MVC3 aspx页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆