ASP.NET MVC ContentPlaceHolders 出现故障?

发布于 2024-09-18 21:10:24 字数 391 浏览 0 评论 0原文

我在标题正下方添加了一个新的 ContentPlaceHolder (HeadContent),以便我可以添加特定于页面的 css 和 js 文件。但是,当我使用母版页创建新视图时,它会放置页面布局的默认文本,以便在页面末尾具有 HeadContent 打开/关闭标记。不幸的是,我在视觉上只是将其视为第一个、第二个和第三个标签,然后开始在最后一个标签中输入页面的 html。但这不是 BodyContent 占位符,因为它是第二个。我必须返回并将它们复制/粘贴到正确的位置。啊。只是为了好玩,我将母版页中的所有标签打乱,只是为了看看视图中会发生什么。果然,VS.NET 忽略了它们在母版页中的顺序,并且每次都以相同的方式重新排序。

为什么 VS 不按照与我的母版页中相同的顺序对占位符标签进行排序?实际上,我如何让它停止并按照我在主页中的顺序执行它?

I added a new ContentPlaceHolder (HeadContent) right below the Title so that I can add page-specific css and js files. But when I create a new View using the master page, it puts the default text of the page layout to have the HeadContent open/close tags at the end of the page. Unfortunately, I visually just see it as the first, second and third tags and start typing in my page's html into the last tag. But this isn't the BodyContent place holder because it is the second one. I have to go back and copy/paste them into the correct place. Ugh. Just for kicks, I scrambled all the tags around in the master page just to see what would happen in the view. Sure enough, VS.NET ignores their order in the master page and reorders them the same way everytime.

Why isn't VS just ordering the place holder tags in the same order as in my master page? Actually, how do I make it stop and just do it in the order I have in my master page?

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

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

发布评论

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

评论(1

神经大条 2024-09-25 21:10:24

Visual Studio 正在做的(我假设)是加载 MVC 视图内容模板。我认为母版页中所有内容都乱序的原因是 Visual Studio Extensiblity 加载模板,然后在模板数据之后添加不在模板中的任何 ContentPlaceHolders。

您可以通过转到程序文件中的 Visual Studio 文件然后转到 Common7\IDE\ItemTemplates\CSharp\Web\MVC2 来查看模板的外观。

还有一个 VB 文件夹。在任何情况下,您都可以打开位于该目录中的 zip 文件并向下钻取,直到到达 .aspx 页面,当您执行“添加新项/视图”时,您将看到 VS 正在将什么插入到您的项目中。

What visual studio is doing (I assume) is loading the MVC View Content Template. I assume the reason all the contents are out of order from your master page is that Visual Studio Extensiblity loads the template then adds any ContentPlaceHolders that are not in the template after the template data.

You can see what the templates look like by going to your Visual Studio file in your Program files then goto Common7\IDE\ItemTemplates\CSharp\Web\MVC2.

There is also a folder for VB. In any case you can open the zip files located in that directory and drill down till you get to the .aspx page and you'll see what VS is inserting into your project when you do a Add New/View.

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