Skip to content

Commit

Permalink
Action results: deriving from the Controller base class, modifying an…
Browse files Browse the repository at this point in the history
… action to return IActionResult, creating and instantiating a Restaurant model, and returning the model instance wrapped in a new ObjectResult
  • Loading branch information
gorohoroh committed Jul 3, 2018
1 parent 2373c1b commit f657b1f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
11 changes: 8 additions & 3 deletions OdeToFoodRider/OdeToFoodRider/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
using Microsoft.AspNetCore.Mvc;
using OdeToFoodRider.Models;

namespace OdeToFoodRider.Controllers
{
public class HomeController
public class HomeController : Controller
{
public string Index()
public IActionResult Index()
{
return "Hello from Rider's Home controller!";
var model = new Restaurant() {Id = 1, Name = "Scott's Pizza Place"};

return new ObjectResult(model);
}
}
}
8 changes: 8 additions & 0 deletions OdeToFoodRider/OdeToFoodRider/Models/Restaurant.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace OdeToFoodRider.Models
{
public class Restaurant
{
public int Id { get; set; }
public string Name { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using OdeToFoodVisualStudio.Models;

namespace OdeToFoodVisualStudio.Controllers
{
public class HomeController
public class HomeController : Controller
{
public string Index()
public IActionResult Index()
{
return "Hello from Visual Studio's Home controller";
var model = new Restaurant { Id = 1, Name = "Scott's Pizza Place" };

return new ObjectResult(model);

// VSRD: Visual Studio doesn't have a quick action to change return type if you try to return something that doesn't match it
// VSRD: Visual Studio's take on Extend/Shrink Selection (Shift+Alt+Plus/Minus) can't extend to a string literal except quotes,
// making it non-trivial to paste text into string literals - it can only extend to the whole string literal
//return Content("Hello from Visual Studio's Home controller");


}
}
Expand Down
13 changes: 13 additions & 0 deletions OdeToFoodVisualStudio/OdeToFoodVisualStudio/Models/Restaurant.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace OdeToFoodVisualStudio.Models
{
public class Restaurant
{
public int Id { get; set; }
public string Name { get; set; }
}
}

0 comments on commit f657b1f

Please sign in to comment.