using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PocoDemo
{
[Controller]
public class Home
{
[ActionContext]
public ActionContext Context { get; set; }
//public IActionResult Today()
//{
// return new ContentResult() { Content= DateTime.Now.ToString("ddd,d MMM") };
//}
//public IActionResult Html()
//{
// return new ContentResult()
// {
// Content="<h1>Hello</h1>",
// ContentType="text/html",
// StatusCode = 200
// };
//}
public IActionResult Index([FromServices] IModelMetadataProvider provider)
{
var viewdata = new ViewDataDictionary<MyViewModel>(provider, new ModelStateDictionary());
viewdata.Model = new MyViewModel() { Title = "Hi" };
return new ViewResult() { ViewName = "index", ViewData = viewdata };
}
//同時處理表單get,post請求的方法
public IActionResult Edit(MyViewModel model)
{
var methond = Context.HttpContext.Request.Method;
switch(methond)
{
case "GET":
return new ViewResult();
case "POST":
return new ContentResult() { Content= model.Title };
default:
return new ContentResult() {Content= "other methods" };
}
}
}
}