Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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 :)