Created
October 7, 2015 13:33
-
-
Save zplume/919860b34b1bf10cb4da to your computer and use it in GitHub Desktop.
Creating a component in MVC 5 to avoid lots of repetition in your Views (DRY!)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--Views\Shared\User.cshtml--> | |
@model MyNamespace.ViewModels.User | |
<div>@Model.Name</div> | |
<!-- | |
This is a very basic example, obviously you'd have more complex nested HTML | |
and more properties in use for it to be worth using a component like this | |
--> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--Views\MainController\MainView.cshtml--> | |
@model MyNamespace.ViewModels.MainModel | |
<h2>Team 1</h2> | |
@Html.Partial("User", Model.User1) | |
@Html.Partial("User", Model.User2) | |
<h2>Team 2</h2> | |
@Html.Partial("User", Model.User3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment