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

DJ Scott
DJ Scott
6,325 Points

I'm getting a "Cannot implicitly convert type 'System.Web.Mvc.ContentResult' to 'string'"

When we convert the return statement into a Content Result. I get an error saying cannot implicitly convert to string. Based on the error I would think that I couldn't set Content to a string, but Content is a string. What am I doing wrong?

My code appears to be the same as in the video...

    public string Detail()
    {
        return new ContentResult()
        {
            Content = "Hello from the comic books controller"
        };

    }

1 Answer

Steven Parker
Steven Parker
216,057 Points

Your "return" statement is passing back a new ContentResult(), but the method "Detail" is declared as returning an item of type string which causes the error.

In the video, this was changed to keep both in sync at about time index 0:30.