Just my two cents, but I always use presentation models to pass any data into my views. Even if it is as simple as int as id.
This makes access to this value trivial, since MVC does all the work for you.
For what it's worth, I usually call my view models like this:
{Controller}{ViewName}ViewModel
This helps to keep things to scale.
Example:
// ~/ViewModels/HomeEditViewModel.cs public class HomeEditViewModel { public int Id { get; set; } } // ~/Controllers/HomeController.cs public IActionResult Edit(int id) { return View(new HomeEditViewModel() { Id = id }); } // ~/Views/Home/Edit.cshtml @model HomeEditViewModel <h1>Id: @Model.Id</h1>
pim Feb 15 '18 at 2:59 p.m. 2018-02-15 14:59
source share