using (HTML.BeginForm(params)) {}
我想要这样做自己的帮手.所以我想做一个简单的例子
using(tablehelper.Begintable(ID){ <th>content etc<th>}
这将在我看来输出
<table> <th>content etc<th></table>
这可能吗?如果是,怎么样?
谢谢
解决方法 当然可以:public static class HTMLExtensions{ private class table : Idisposable { private Readonly TextWriter _writer; public table(TextWriter writer) { _writer = writer; } public voID dispose() { _writer.Write("</table>"); } } public static Idisposable Begintable(this HTMLHelper HTML,string ID) { var writer = HTML.VIEwContext.Writer; writer.Write(string.Format("<table ID=\"{0}\">",ID)); return new table(writer); }}
接着:
@using(HTML.Begintable("abc")){ @:<th>content etc<th>}
将产生:
<table ID="abc"> <th>content etc<th></table>
我也建议你阅读约Templated Razor Delegates.
总结以上是内存溢出为你收集整理的c# – 为自己的帮手创建使用?像Html.BeginForm全部内容,希望文章能够帮你解决c# – 为自己的帮手创建使用?像Html.BeginForm所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)