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 trial

C# ASP.NET MVC Basics Controllers Using Action Result Types

Simon Sporrong
Simon Sporrong
35,097 Points

Problem with adding the Content. Get a "unreachable code detected

Hi!

I'm getting an error: "Cannot assign to 'Content' because it is a 'method group'." And also a warning: "Unreachable code detected". What am I doing wrong?

I should point out that i'm using a Mac with Visual Studio Community 2017, so the solution doesn't look exactly like the video. For example I have another Controller named HomeController wich was added for me when creating the project.

Grateful for any help!

using System;
using System.Web.Mvc;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace ComicBookGallery.Controllers
{
   public class ComicBookController : Controller
    {
        public ContentResult Detail()
        {
            return new ContentResult();
            {
                Content = "Hello from the comic book controller"
            };
        }
    }
}
S Hedron
S Hedron
17,123 Points

Hi!

Easy fix here, you just need to remove the semi-colon directly after ContentResult();

The rest is fine.

1 Answer

Simon Sporrong
Simon Sporrong
35,097 Points

I'm the dumbest boy in school. Thank you S Hedron :)