text
stringlengths 0
13.4k
|
|---|
public class TodoViewModel
|
{
|
public TodoItem[] Items { get; set; }
|
}
|
}
|
Now that you have some models, it's time to create a view that will take
|
a TodoViewModel and render the right HTML to show the user their to-
|
do list.
|
26
|
Create models
|
27
|
Create a view
|
Create a view
|
Views in ASP.NET Core are built using the Razor templating language,
|
which combines HTML and C# code. (If you've written pages using
|
Handlebars moustaches, ERB in Ruby on Rails, or Thymeleaf in Java,
|
you've already got the basic idea.)
|
Most view code is just HTML, with the occasional C# statement added in
|
to pull data out of the view model and turn it into text or HTML. The C#
|
statements are prefixed with the @ symbol.
|
The view rendered by the Index action of the TodoController needs to
|
take the data in the view model (a sequence of to-do items) and display it
|
in a nice table for the user. By convention, views are placed in the
|
Views directory, in a subdirectory corresponding to the controller name.
|
The file name of the view is the name of the action with a .cshtml
|
extension.
|
Create a Todo directory inside the Views directory, and add this file:
|
Views/Todo/Index.cshtml
|
@model TodoViewModel
|
@{
|
ViewData["Title"] = "Manage your todo list";
|
}
|
<div class="panel panel-default todo-panel">
|
<div class="panel-heading">@ViewData["Title"]</div>
|
<table class="table table-hover">
|
<thead>
|
<tr>
|
<td>✔</td>
|
<td>Item</td>
|
<td>Due</td>
|
28
|
Create a view
|
</tr>
|
</thead>
|
@foreach (var item in Model.Items)
|
{
|
<tr>
|
<td>
|
<input type="checkbox" class="done-checkbox">
|
</td>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.