簡體   English   中英

沒有代碼隱藏的ASP.Net

[英]ASP.Net without codebehind

我想創建一個沒有所有代碼隱藏和設計器東西的ASP.Net頁面。 基本上我想回到ASP經典,但保留CLR和基類庫使.Net非常好。 我想要一個像這樣的頁面:

<html>
<body>
<div>

  <%
    int customerID = Request.QueryString["CustomerID"];
    //Customer and DataAccess classes come from an extenal assembly
    Customer customer = DataAccess.GetCustomer(customerID); 
  %>
  You asked for Customer with ID: <%=customerID;%><br />
  Name: <%=customer.Name;%><br />
  Phone: <%=customer.Phone;%><br />


</div>
</body>
</html>

然而,似乎有一些問題。

  • Request對象僅在Page對象中可用。 我希望完全刪除代碼隱藏和設計器頁面。
  • 沒有intellisense
  • 在我深入研究之前我應該​​注意什么?
  • 不知道如何開始拉入外部庫

如果你不想,你不需要在代碼隱藏中做任何事情。

要導入名稱空間,請使用import指令:

<%@ Import namespace="System.Web" %>

要導入外部庫,請使用Assembly指令:

<%@ Assembly Name="YourAssemblyName" %>

導入System.Web將允許您對HttpContext.Current.Request對象進行智能感知訪問。 它還將為您提供該命名空間中任何其他對象的智能感知,就像代碼文件一樣。

我認為你最好的辦法是看看ASP.NET MVC,特別是使用Razor View Engine。

盡管如此,你仍然會有一些工具。

HttpContext.Current.Request將為您提供請求。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM