在双引号之间嵌入 ContentPlaceHolder

发布于 2024-07-17 19:45:19 字数 735 浏览 4 评论 0 原文

我正在使用 .NET MVC,并且在视图页面中我设置了一个 contentplaceholder,其中包含要在母版页上使用的 ID,如下所示:

查看页面:

<asp:Content ID="CDomBodyId" ContentPlaceHolderID="DomBodyId" runat="server">LmpDemoRequests</asp:Content>

母版页:

<body id='<asp:ContentPlaceHolder ID="DomBodyId" runat="server"></asp:ContentPlaceHolder>'>

因此在这种特殊情况下,body 标记将像这样在母版页上呈现最终的 HTML 页面:

<body id='LmpDemoRequests'>

我希望在 body id 标记周围使用双引号,但是像下面这样反转引号会使智能感知无法找到 contentplaceholder,在编译时给我很多警告。

<body id="<asp:ContentPlaceHolder ID='DomBodyId' runat='server'></asp:ContentPlaceHolder>">

有没有办法解决?

I am using .NET MVC, and within view pages I set a contentplaceholder that contains an ID to be used on the master page like so:

View page:

<asp:Content ID="CDomBodyId" ContentPlaceHolderID="DomBodyId" runat="server">LmpDemoRequests</asp:Content>

Master page:

<body id='<asp:ContentPlaceHolder ID="DomBodyId" runat="server"></asp:ContentPlaceHolder>'>

So in this particular case, the body tag would render like this on the final HTML page:

<body id='LmpDemoRequests'>

I would like to have double quotes around the body id tag, but inverting the quotes like the following makes intellisense unable to find the contentplaceholder, giving me a lot of warnings when I compile.

<body id="<asp:ContentPlaceHolder ID='DomBodyId' runat='server'></asp:ContentPlaceHolder>">

Is there any way around this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

刘备忘录 2024-07-24 19:45:19

这是 ASP.NET 编辑器的问题。 它不是 MVC 特有的。 我认为解决方法非常好,而且我没有看到具体的缺点。

This is an issue with ASP.NET editor. It's not specific to MVC. I think the workaround is pretty good and I don't see a specific drawback.

甜柠檬 2024-07-24 19:45:19

尝试将 BodyID 声明为 MasterPage 的属性。 在“查看”页面中设置其值。 然后你可以做类似的事情
<代码>

'>;

Try declaring BodyID as a property of your MasterPage. Set its value in the View pages. Then you can do something like

<html>
<body='<%= BodyID %>'>
</body
</html>

金橙橙 2024-07-24 19:45:19

不确定我是否误解了您的问题,但您也可以添加:

<body id="site" runat="server"></body>

然后在您的页面上访问它

HtmlControl body = (HtmlControl)Master.FindControl("site");
body.Attributes.Add("class", "LmpDemoRequests");

我希望我正确理解您的问题。

Not sure if I have misunderstood your question, but you can also add:

<body id="site" runat="server"></body>

And then access it on your page

HtmlControl body = (HtmlControl)Master.FindControl("site");
body.Attributes.Add("class", "LmpDemoRequests");

I hope I understood your correctly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文