2013-07-10 38 views
0

我有一個MVC 3應用程序,我創建了一個.aspx頁面,我正在嘗試將其納入到我的項目中。在.aspx頁面看起來是這樣的:無法在我的MVC 3 Web應用程序中查看.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

您正在使用此頁面的WebForms,而不是MVC,因此View()將不起作用。在您的應用中使用WebForms頁面是完全合法的,但您無法使用MVC方式。

看來你不能在你的Views目錄中放置一個WebForms頁面,即使你可以,你也不應該這樣做。你需要把它放在別的地方在你的Web應用程序 - 讓我們說/HomePages

然後,你只需要做一個直線上升的重定向,如:

public ActionResult Admin() { 
    return Redirect("~/HomePages/Admin.aspx"); 
} 
+0

剛搬進到一個新的文件夾,它像一個魅力工作,謝謝! – user2569124

相關問題