
我想实现类似的东西.我希望它获取您要呈现的视图的名称,以及一些其他变量,并在容器中呈现内容.
例如:
public static class WindowHelper{ public static string Window(this HTMLHelper helper,string name,string vIEwname) { var sb = new StringBuilder(); sb.Append("<div ID='" + name + "_Window' class='window'>"); //Add the contents of the partial vIEw to the string builder. sb.Append("</div>"); return sb.ToString(); }} 有人知道怎么做吗?
解决方法 RenderPartial扩展被编程为直接呈现给Response对象…您可以在源代码中看到它们:....).Render(vIEwContext,this.VIEwContext.httpContext.Response.Output);
这意味着如果你稍微改变一下你的方法,你可以完成你想要的.您可以执行以下 *** 作,而不是将所有内容附加到StringBuilder:
using System.Web.Mvc.HTML;public static class WindowHelper{ public static voID Window(this HTMLHelper helper,string vIEwname) { var response = helper.VIEwContext.httpContext.Response; response.Write("<div ID='" + name + "_Window' class='window'>"); //Add the contents of the partial vIEw to the string builder. helper.RenderPartial(vIEwname); response.Write("</div>"); }} 请注意,包括System.Web.Mvc.HTML允许您访问RenderPartial()方法.
总结以上是内存溢出为你收集整理的c# – Html Helper,RenderPartial如何工作?如何实现可以从局部视图中引入内容的帮助程序?全部内容,希望文章能够帮你解决c# – Html Helper,RenderPartial如何工作?如何实现可以从局部视图中引入内容的帮助程序?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)