每天學點MVC 【用戶自定義控件】


Asp.Net MVC2中 說到用戶自定義控件,就一肚子火氣,折騰過我好多回,這回總算看了點所以然

 什么都不說了,code附上

 1 情況一:通過controller創建的用戶自定義控件

 2  // Controllers  :TestAscx
 4 
 5   public ActionResult TestAscx()
 6         {
 7             Ascx ascx =  new Ascx();
 8              return  PartialView(ascx);
 9         }
10  // View  :TestAscx.ascx
11 
12 <%@ Control Language= " C# " Inherits= " System.Web.Mvc.ViewUserControl<Ascx> " %>
13 在里面可以填寫你想要寫的東東
14 
15   // 調用控件
16  View: index.aspx
17 
18 <% Html. RenderAction( " TestAscx "); %>

 

 情況二:調用ASP.NET 模式的用戶自定義控件,eg:footer.ascx

Controller中不需要任何東東,只需要在需要調用的地方

<% Html. RenderPartial( " footer "); %>

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM