| 饼子天空 |
|
|||
| 个人程序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"); %>
程序员问答社区,解决您的IT难题
|
![]() |
|
| Copyright © 饼子天空 | Powered by: 博客园 模板提供:沪江博客 |