7

I am working on an asp.net MVC4 application. In my layout page, I have the following code

@RenderSection("page-specific", required: false) 

and In my view which uses the above layout, I have

@section page-specific{
  <script src="~/Scripts/page-specific.js" type="text/javascript"></script>
}

When I run my application, it gives me the following error

Sections cannot be empty. The "@section" keyword must be followed by a block of markup surrounded by "{}"

But all I want to do is include some page specific styles and javascript. I dont want to include any HTML markup in this particular section. How can I do this while avoiding the empty section error?

1
  • a script tag IS markup. There must be something else going on here. Are you sure you are looking at the correct code? Commented Sep 27, 2012 at 18:05

1 Answer 1

8

Try naming it pageSpecific. I haven't tried using a hyphen in a section name before, but I have a feeling mvc might not like that.

Sign up to request clarification or add additional context in comments.

2 Comments

That did the trick! Looks like hyphens aren't allowed in section names. I wish the error was more descriptive though. Oh Well, I always learn something new everyday.
Glad that fixed it. I was looking all over for the naming requirements for a section, and couldn't find anything. I'd assume you have to follow the same naming rules as a variable in your C#/VB code (as in not using reserved words or illegal characters).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.