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 trialJess Dever
5,918 PointsIn the 'Detail' method, are you returning a call to the 'Content' method?
I am getting the error message above. What I don't understand is that my code is identical to the example and is not working. What am I missing?
3 Answers
Steven Parker
231,275 PointsThe challenges are designed to give you an opportunity to be creative, and can never be resolved by just copying identical code from the video examples.
If you'd like help in spotting the actual issue, please show your code here.
Jess Dever
5,918 PointsSorry, I'm not sure where you want me to post the code. The link you provided was to more videos. I had checked a box that said share my code initially. If you could provide a little more clarity on sharing the code that would be great. Otherwise, the code that is giving me the error is posted in my comment above.
You're right it's not identical. The difference is in the example the class is an ActionResult, rather than a ContentResult, which is what the problem is asking for. Again, any help would be appreciated, and if you can give some guidance on getting you the code, I'll do my best. Just not sure what you're looking for.
Steven Parker
231,275 PointsThe code as given is OK this time, but in future use Markdown formatting to preserve the code appearance. The link is to a video that explains the use of Markdown.
Jess Dever
5,918 PointsI thought I was calling it by using:
new ContentResult()
That's not what calling a method is? I've googled how to call the Content method, but I'm really not understanding. Can you please explain how to call the Content method?
Jess Dever
5,918 PointsAlso, I've tried variations, so it's not for lack of an attempt at creativity. I can list all of the things I've tried. But I just don't understand what to do. If it would be helpful for me to list them please let me know. But I just don't understand and I'm asking for help because it feels like I'm just spinning my wheels in mud and just guessing at this point.
Steven Parker
231,275 PointsIf you are new to C#, you may have skipped some important preliminary instruction.
See the comment I added to my original answer.
Jess Dever
5,918 PointsJess Dever
5,918 Pointsusing System.Web.Mvc;
namespace Treehouse.Controllers { public class VideoGamesController : Controller { public ActionResult Detail() { return new ContentResult() { Content = "Welcome to the Video Game Detail page!" }; } } }
Steven Parker
231,275 PointsSteven Parker
231,275 PointsThe instructions say to make "a call to the base controller's Content method" and pass the string to it.
But this code is not calling the Content method and making an assignment using the string instead.
Also, you can rely on .Content() to construct the content result object for you.
Steven Parker
231,275 PointsSteven Parker
231,275 PointsThe keyword "new" is specifically to construct an object. You don't need to do that here because the method does it for you.
The general syntax for calling a method is
object_or_class_name.method_name(arguments_if_any)
.Now even though this course is listed as "beginner", you might benefit from the suggestions made in the Teacher's Notes in the first video regarding "courses ... to complete before viewing this workshop". In particular: