Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialLuke Walz
5,271 PointsError when I click on my Links page
I get a compilation error when I run the Links page.
Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1528: Expected ; or = (cannot specify constructor arguments in declaration)
Source Error:
Line 69: #line default Line 70: #line hidden Line 71: BeginContext("~/Views/Links/Index.cshtml", 61, 35, true); Line 72: Line 73: WriteLiteral("</h2>\r\n\r\n<ul>\r\n <li>\r\n <a");
Source File: C:\Users\Luke\AppData\Local\Temp\Temporary ASP.NET Files\vs\864bc8f4\88924fc9\App_Web_index.cshtml.c2de679c._emjsctk.0.cs Line: 71
Show Detailed Compiler Output:
Show Complete Compilation Source:
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1073.0
3 Answers
Gavin Ralston
28,770 Points@{ ViewBag.Title = "Links"; }
<h2>@{ViewBag.Title}</h2> // You don't need braces here.
<ul>
<li>
<a href="www.google.com">Google</a>
</li>
<li>
<a href="www.bing.com">Bing</a>
</li>
</ul>
Try removing the braces from the h2 element. Just @ViewBag.Title should be enough. The braces might very well be the difference between dropping into C# to actually execute a code block, versus the @ sign by itself in front of a variable which would probably signify just accessing the value in the ViewBag.Title property.
See how at the top you use the braces to actually make the assignment to the Title property/field? Calling it should be as simple as just plugging it in to the HTML without the braces. (But with the @ sign so you're signifying it's a Razor statement.
<h2>@ViewBag.Title</h2>
Cindy Lea
Courses Plus Student 6,497 PointsPost the code. Looks like you might be missing a ; or = somewhere
Luke Walz
5,271 Points@{ ViewBag.Title = "Links"; }
<h2>@{ViewBag.Title}</h2>
<ul> <li> <a href="www.google.com">Google</a> </li>
<li>
<a href="www.bing.com">Bing</a>
</li>
</ul>
Luke Walz
5,271 PointsLuke Walz
5,271 PointsThat was it. Thanks a ton for the clarification!
Gavin Ralston
28,770 PointsGavin Ralston
28,770 PointsAwesome. Glad I could help!