开发者

ASP.NET MVC ContentPlaceHolders out of order?

开发者 https://www.devze.com 2023-01-15 23:19 出处:网络
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 t

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 t开发者_运维知识库o 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消