更换了Itemplate在MVC? [英] Replacement for ITemplate in MVC?
问题描述
我目前正在运行的网站,我用从继承了Itemplate包裹我所有的用户控件中的一个控制。
I am currently running a website, i use a control that inherits from ITemplate to wrap all my usercontrols in.
基本上它是什么,是一个不错的边框的表,我能够在那里倾倒什么,所以如果我改变容器模板,所有的容器进行的跨站点改变...
basically what it is, is a table with a nice border, and i am able to dump anything in there, so if i change the container template, all the containers accross the site changes...
我现在是在重建使用MVC 2的整个应用程序的过程中,没有人知道的一种方式,我可以实现MVC相同的容器之类的模板?
I am now in the process of rebuilding the entire application using MVC 2, does anyone know of a way i can achieve the same "Container" like template in MVC?
推荐答案
我设法感谢名单下面是一个例子:
I managed Thanx here is an example:
public static class Block
{
public static BlockHelper BeginBlock(this System.Web.Mvc.HtmlHelper content, string title)
{
return new BlockHelper(content, title);
}
}
public class BlockHelper : IDisposable
{
private readonly HtmlHelper _content;
private readonly HtmlHelper _title;
public BlockHelper(System.Web.Mvc.HtmlHelper content, string title)
{
_content = content;
StringBuilder sb = new StringBuilder();
sb.Append("<div>");
sb.Append("<div><h1>" + title + "</h1></div>");
_content.ViewContext.Writer.Write(sb.ToString());
}
public void Dispose()
{
StringBuilder sb = new StringBuilder();
sb.Append("</div>");
_content.ViewContext.Writer.Write(sb.ToString());
}
}
然后我基本上都采用它,如下所示:
and then i basically uses it as follows:
<% using( Html.BeginBlock("TITLE>CONTENT GOES HERE<%}%>
这篇关于更换了Itemplate在MVC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!