我有一个MVC 3应用程序,我创建了一个.aspx页面,我试图将其合并到我的项目中。 .aspx页面如下所示:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Admin.aspx.cs" Inherits="TabletWebApp.Views.Home.Admin" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="ID" DataSourceID="SqlDataSource1" ForeColor="#333333"
GridLines="None" onselectedindexchanged="GridView1_SelectedIndexChanged">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="machineName" HeaderText="machineName"
SortExpression="machineName" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:TabletWebAppConnectionString %>"
SelectCommand="SELECT [ID], [machineName] FROM [MachineNames] ORDER BY [ID]"></asp:SqlDataSource>
</div>
<asp:GridView ID="GridView2" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="ID" DataSourceID="SqlDataSource2" ForeColor="#333333"
GridLines="None" onselectedindexchanged="GridView2_SelectedIndexChanged">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="parameterName" HeaderText="parameterName"
SortExpression="parameterName" />
<asp:BoundField DataField="machineID" HeaderText="machineID"
SortExpression="machineID" />
<asp:BoundField DataField="minVal" HeaderText="minVal"
SortExpression="minVal" />
<asp:BoundField DataField="maxVal" HeaderText="maxVal"
SortExpression="maxVal" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:TabletWebAppConnectionString %>"
SelectCommand="SELECT [ID], [parameterName], [machineID], [minVal], [maxVal] FROM [MachineParameters] ORDER BY [ID], [machineID], [parameterName]">
</asp:SqlDataSource>
</form>
</body>
</html>
在控制器中我简单地称之为:
public ActionResult Admin()
{
return View();
}
但是当我尝试查看页面时,我收到错误“'〜/ Views / Home / Admin.aspx'中的视图必须从ViewPage,ViewPage,ViewUserControl或ViewUserControl派生。”!
Picture of resulting error message
我一直在寻找谷歌,发现这个Using the ASP.NET MVC source code to debug your app
但是一旦删除了system.web.mvc引用,我的项目就出现了构建错误。任何想法?
答案 0 :(得分:0)
您正在为此页面使用WebForms,而不是MVC,因此View()
将无效。在你的应用程序中拥有一个WebForms页面是完全合法的,但你无法使用MVC方式。
您似乎无法在您的Views
目录中放置WebForms页面,即使可以,也不应该。您需要将其放在网络应用中的其他位置 - 让我们说/HomePages
然后你只需要进行直接重定向,例如:
public ActionResult Admin() {
return Redirect("~/HomePages/Admin.aspx");
}