using Microsoft.AspNet.Mvc;
using MvcSample.Web.Models;
namespace MvcSample.Web
{
public class HomeController : Controller
{
public IActionResult Index()
{
return View("MyView", User());
}
public IActionResult ValidationSummary()
{
ModelState.AddModelError("something", "Something happened, show up in validation summary.");
return View("ValidationSummary");
}
///
/// Action that shows metadata when model is null.
///
public IActionResult Create()
{
return View();
}
///
/// Action that shows metadata when model is non-null.
///
///
public IActionResult Edit()
{
ViewBag.Gift = "the banana";
ViewData.Model = new User { Name = "Name", Address = "Address in a State", Age = 37, };
return View("Create");
}
///
/// Action that exercises query\form based model binding.
///
public IActionResult SaveUser(User user)
{
return View("MyView", user);
}
///
/// Action that exercises input formatter
///
public IActionResult Post([FromBody]User user)
{
return View("MyView", user);
}
public IActionResult Something()
{
return new ContentResult
{
Content = "Hello World From Content"
};
}
public IActionResult Hello()
{
return Result.Content("Hello World");
}
public void Raw()
{
Context.Response.WriteAsync("Hello World raw");
}
public User User()
{
User user = new User()
{
Name = "My name",
Address = "My address",
Alive = true,
Age = 13,
GPA = 13.37M,
Password = "Secure string",
Dependent = new User()
{
Name = "Dependents name",
Address = "Dependents address",
Alive = false,
},
};
return user;
}
///
/// Action that exercises default view names.
///
public IActionResult MyView()
{
return View(User());
}
}
}