饼子天空  
个人程序Blogs

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

 

 

posted on 2012-01-12 13:31  饼子天空  阅读(4567)  评论(0编辑  收藏  举报