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

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
231,268 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.