gistlib
To create a controller that returns a viewmodel in C#, you can follow these steps:
main.cspublic class MyViewModel { public string Property1 { get; set; } public int Property2 { get; set; } } 110 chars6 lines
public class MyViewModel { public string Property1 { get; set; } public int Property2 { get; set; } }
main.cspublic class MyController : Controller { public IActionResult Index() { var viewModel = new MyViewModel { Property1 = "Hello, World!", Property2 = 42 }; return View(viewModel); } } 250 chars14 lines
public class MyController : Controller { public IActionResult Index() { var viewModel = new MyViewModel { Property1 = "Hello, World!", Property2 = 42 }; return View(viewModel); } }
main.cs@model MyNamespace.MyViewModel <h1>@Model.Property1</h1> <p>@Model.Property2</p> 82 chars5 lines
@model MyNamespace.MyViewModel <h1>@Model.Property1</h1> <p>@Model.Property2</p>
gistlibby LogSnag