.Net Core 2.0 How to instantiate and/or pass a model from Controller to Razor Page?
user4820 Published in September 21, 2018, 8:03 am
I came to know that Razor page only works with model which is subclassed from PageModel. So I purposely create this class in the "Code-behind" of the generated razor page. I instantiate this class and pass it to the Page and the "Model" is still NULL.
public ActionResult Index()
long count = _service.GetData();
IndexModel model = new IndexModel(_service.GetSortedData());
return View("~/Pages/MyPage/Index.cshtml", model);
@foreach (var data in Model.Data) <= Model is NULL