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 trialAmy Shah
25,337 Pointsproblem with ASP.NET basics question about using action result
I am trying to find the answer to this question
Challenge Task 1 of 1
Update the provided VideoGamesController.Detail action method to use ActionResult for its return type instead of a string. In the action method, return the result of a call to the base controller's Content method. Keep the content the same by passing the string literal "Welcome to the Video Game Detail page!" to the Content method. Bummer! Your code could not be compiled. Please click on "Preview" to view the compiler errors. Restart Preview Get Help Recheck work VideoGamesController.cs
tent 1 using System.Web.Mvc; 2 ā 3 namespace Treehouse.Controllers 4 { 5 public class VideoGamesController : Controller 6 { 7 public actionResult Detail() 8 { 9 return new ContentResult() 10 { 11 return Content("Welcome to the Video Game Detail page!"); 12 } 13
14 } 15 } 16 }
using System.Web.Mvc;
namespace Treehouse.Controllers
{
public class VideoGamesController : Controller
{
public actionResult Detail()
{
return new ContentResult()
{
return Content("Welcome to the Video Game Detail page!");
}
}
}
}
6 Answers
Amy Shah
25,337 Pointsthis answer did work: using System.Web.Mvc;
namespace Treehouse.Controllers { public class VideoGamesController : Controller { public ActionResult Detail() { return Content("Welcome to the Video Game Detail page!");
}
}
}
bkraider
7,837 PointsThe Controller class provided by ASP.NET MVC has the method ContentResult. The method name is Content and it takes string as the input parameter.
protected internal ContentResult Content(string content);
So in the Detail method we change the return type to the ActionResult and call the method Content and pass it a string value
using System.Web.Mvc;
namespace Treehouse.Controllers
{
public class VideoGamesController : Controller
{
public ActionResult Detail()
{
return Content("Welcome to the Video Game Detail page!");
}
}
}
Steven Parker
231,268 PointsI see two issues:
- you wrote "actionResult" (lower-case "a"), but the return type should be "ActionResult" (capital "A")
- you only need the inner return statement to directly return the result of calling Content
Amy Shah
25,337 PointsAmy Shah
25,337 Pointsthe above is the link to the question
Steven Parker
231,268 PointsBy using the "Get Help" button, the system already created a link to the challenge for you, in the form of the "View Challenge" button in the upper right of the page.
Amy Shah
25,337 PointsI tried this but it did not work
using System.Web.Mvc;
namespace Treehouse.Controllers { public class VideoGamesController : Controller { public ActionResult Detail() { return Content = ("Welcome to the Video Game Detail page!"); } } }
Steven Parker
231,268 PointsThere is a stray equal sign ("=") stuck between the call to Content and its parameter.
Jeanette Brown
20,485 Pointsusing System.Web.Mvc;
namespace Treehouse.Controllers { public class VideoGamesController : Controller
{ public string Detail() { return "Welcome to the Video Game Detail page!"; }
} }
Steven Parker
231,268 PointsSteven Parker
231,268 PointsAmy Shah ā Good job. That's exactly what I was suggesting.
But normally you would give "best answer" to the answer that gave you the information to resolve your problem.