-
-
Save HamidMosalla/89f602d37a0083e6b730e63771e02c94 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Person | |
{ | |
public string FirstName { get; set; } | |
public string LastName { get; set; } | |
} | |
public class HomeController : Controller | |
{ | |
public IActionResult IndexWithId(int id) | |
{ | |
return View(); | |
} | |
public ActionResult IndexActionResult() | |
{ | |
return View("Index"); | |
} | |
public ViewResult IndexViewResult() | |
{ | |
return View(); | |
} | |
public JsonResult JsonActionResult() | |
{ | |
var data = new { Name = "Alex", LastName = "DeLarge" }; | |
return Json(data); | |
} | |
public PartialViewResult PartialViewActionResult() | |
{ | |
var model = new List<int> { 2, 3 }; | |
return PartialView("_PartialViewActionResult", model); | |
} | |
//writes the result of component to response, notice that you can directly call it in a controller | |
//IViewComponentResult should be returned from a Class that inherent form ViewComponent | |
public ViewComponentResult HomeSliderComponent() | |
{ | |
return ViewComponent("HomeSlider", new { id = 4 }); | |
} | |
//returns 200 with the content and specified media type for the content | |
public ContentResult ContentActionResult() | |
{ | |
return Content("{Name: 'Hamid'}, {Name: 'Stanley'}", new MediaTypeHeaderValue("application/json")); | |
} | |
//returns 200 OK which is empty | |
public EmptyResult EmptyActionResult() | |
{ | |
return new EmptyResult(); | |
} | |
public Person PocoResult() | |
{ | |
return new Person { FirstName = "Major", LastName = "Bob" }; | |
} | |
public List<Person> GetAllPersons() | |
{ | |
return new List<Person> { new Person { FirstName = "Alex", LastName = "DeLarge" }, new Person { FirstName = "Major", LastName = "Bob" } }; | |
} | |
public int IntResult() | |
{ | |
return 2; | |
} | |
public string StringResult() | |
{ | |
return "Major Bob ?"; | |
} | |
[NonAction] | |
public Person YouShallNotPass() | |
{ | |
return new Person { FirstName = "James", LastName = "Gandolfini" }; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment