Skip to content

Instantly share code, notes, and snippets.

@Deathspike
Created December 11, 2014 11:12
Show Gist options
  • Select an option

  • Save Deathspike/ff90e5058a51e69ea62f to your computer and use it in GitHub Desktop.

Select an option

Save Deathspike/ff90e5058a51e69ea62f to your computer and use it in GitHub Desktop.
ASP.NET MVC Strong-Typed Views with ViewModels
@model MyViewModel
<div>My strong-typed name is @Model.Name</div>
using System.Web.Mvc;
namespace MyExample
{
public class MyController : Controller
{
[HttpGet]
public ActionResult Index()
{
return View(new MyViewModel
{
Name = "Roel van Uden"
});
}
}
}
namespace MyExample
{
public class MyViewModel
{
public string Name { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment