母版页中的条件内容占位符
我的项目中有两个母版页,一个用于 Web 视图,另一个用于电子邮件。在 Web 母版页中,有一个占位符用于放置页面特定的 JavaScript,如果页面正在使用此占位符,并且我尝试以编程方式更改母版页以作为电子邮件发送,则服务器会因为找不到占位符而崩溃。
有没有办法改变行为,以便如果找不到占位符,它就不会包含该位?我想也许在我的页面基类上循环占位符和内容标记的集合并删除不匹配的标记,但我不确定页面生命周期中是否有这样做的好点。
如果这有什么区别的话,我正在使用 MVC 而不是 WebForms。
I have two master pages in my project, one for web views and another for emails. In the web master page is a placeholder to put page specific JavaScript, if a page is using this and I try to programmatically change the masterpage to send as an email the server falls over as it can't find the placeholder.
Is there a way to change the behaviour so that if a placeholder can't be found it just doesn't include that bit? I'm thinking maybe on my page base class looping over a collection of placeholders and content tags and removing the ones that don't match up, but I'm not sure if there's a good point in the page lifecycle to do this.
I'm using MVC not WebForms if this makes a difference.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 ContentPlaceHolder 添加到邮件母版页中并将visible 属性设置为 false,并且该占位符页面中的内容将不会呈现。
Add the ContentPlaceHolder into the mail masterpage and set the visible property to false and the content from the page for that placeholder won't render.
您不能拥有具有不存在的 ContentPlaceHolderID 的内容控件。
为什么不直接提供一个空的内容控件,而不是取出 ContentPlaceHolder?它不会渲染任何东西。
You can't have a Content control with a ContentPlaceHolderID that doesn't exist.
Instead of taking the ContentPlaceHolder out, why don't you just provide an empty Content control? It'll just render nothing.