I am trying to run my first ASP.NET MVC application. I created a controller and view. Data is taken from the Database.
Here is the view
@model WebApplication4.Models.User
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>会員情報画面</title>
</head>
<body>
@using (Html.BeginForm())
{
<style type="text/css">
table {
border-collapse: collapse;
}
th {
background: #ccc;
text-align: left;
}
td, th {
border: 1px solid #800;
padding: 4px;
}
</style>
<table>
<tr>
<th style="background: #ffffff; border: 1px solid #200;">
<p> 検索用 </p>
</th>
<th style="background: #ffffff ;border: 1px solid #200;">
<p> 追加・更新・削除 </p>
</th>
</tr>
<tr>
<th>
<p>
会員コード: @Html.TextBoxFor(x => x.numer)
会員名: @Html.TextBoxFor(x => x.name)
</p>
<p>
@Html.CheckBoxFor(m => m.sexcb, false) @Html.Label("男性")
@Html.CheckBoxFor(m => m.sexcb, false) @Html.Label("女性")
@Html.CheckBoxFor(m => m.sexcb, false) @Html.Label("その他")
</p>
<p>生年月日: <input type="date" name="calendar" min="1900-01-01" max="2019-01-01"> ~ <input type="date" name="calendar" min="1900-01-01" max="2019-01-01"></p>
<p>ポイント: @Html.TextBoxFor(x => x.point) ~ @Html.TextBoxFor(x => x.point)</p>
</th>
<th>
<p>
会員コード: @Html.TextBoxFor(x => x.numer)
会員名: @Html.TextBoxFor(x => x.name)
</p>
<p>
@Html.RadioButtonFor(model => model.sex, "T") @Html.Label("男性")
@Html.RadioButtonFor(model => model.sex, "C") @Html.Label("女性")
@Html.RadioButtonFor(model => model.sex, "C") @Html.Label("その他")
</p>
<p>生年月日: <input type="date" name="calendar" min="1900-01-01" max="2019-01-01"></p>
<p>ポイント: @Html.TextBoxFor(x => x.point)</p>
</th>
</tr>
</table>
<h1></h1>
<table cellspacing="0" border="1">
<tr>
<th></th>
<th colspan="1">会員コード</th>
<th colspan="1">会員名</th>
<th colspan="1">会員名カナ</th>
<th colspan="1">会員性別</th>
<th colspan="1">会員生年月日</th>
<th colspan="1">会員ポイント</th>
<th colspan="1">バージョン</th>
</tr>
</table>
@RenderBody()
<p>
<input style="padding: 20px;" type="submit" value="検索" />
<input style="padding: 20px;" type="submit" value="クリア" />
<input style="padding: 20px;" type="submit" value="追加" />
<input style="padding: 20px;" type="submit" value="更新" />
<input style="padding: 20px;" type="submit" value="削除" />
<input style="padding: 20px;" type="submit" value="ビデオ情報画面" />
</p>
}
</body>
</html>
Here is my controller code.
namespace WebApplication4.Controllers
{
public class UserController : Controller
{
private IUserRepository repository;
public UserController(IUserRepository repo)
{ repository = repo; }
public ViewResult List() => View(repository.Users);
}
}
However, when the project can run but when I try to navigate User page I get the following error:
InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1[WebApplication4.Models.User]', but this ViewDataDictionary instance requires a model item of type 'WebApplication4.Models.ViewModels.UserListViewModel'.