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"); %>

 

 

相关文章:

  • 2022-12-23
  • 2021-07-22
  • 2021-10-13
  • 2022-12-23
  • 2021-09-03
  • 2021-09-06
  • 2022-03-02
猜你喜欢
  • 2022-01-27
  • 2021-08-14
  • 2021-12-15
  • 2021-11-18
  • 2022-12-23
  • 2021-09-01
相关资源
相似解决方案