私は、私は非常に長い時間が経過した後、フロントエンドの開発を行うと、フロントエンドに取り組んでいますStudentController、Index.cshtmlと中央layout.cschtmlと呼ばれるコントローラ、どのように、同じコントローラ上の別のアクションにビューをリダイレクトする
を持っていますasp.net mvcは静かな私のための挑戦ですので、何かが間違っている場合は私を許してください。
私が達成しようとしているのは、自分のアプリケーションを実行しているときに完璧に実行されますが、リンクをクリックすると学生が正常にStudent Indexビューに移動し、StudentControllerのIndexメソッドにヒットします。
しかし、私はIndexビューに新しいリンクを作成をクリックしたとき、それはエラーになります(一番下を参照)、誰かが私が間違っているのものを導くことができます....
StudentController
public StudentController(){}
public ActionResult Index()
{
var students =_studentDb.GetAll();
return View(students);
}
[HttpPost]
public ActionResult Create(Student student)
{
var result = _studentDb.Insert(student);
return View("Create");
}
_layout.chtml
<ul class="nav navbar-nav">
<li>@Html.ActionLink("Home", "Index", new { Controller = "Home", Area = "Common" })</li>
<li>@Html.ActionLink("Student", "Index", new { Controller = "Student", Area = "User" })</li>
<li>@Html.ActionLink("New Student", "Index", new { Controller = "CreateStudent", Area = "User" })</li>
</ul>
Index.chtml
@model IEnumerable<Student>
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create",new {Controller="Student",Area="User" })
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.FirstName)
</th>
<th>
@Html.DisplayNameFor(model => model.MiddleName)
</th>
<th>
@Html.DisplayNameFor(model => model.LastName)
</th>
<th>
@Html.DisplayNameFor(model => model.Gender)
</th>
<th>
@Html.DisplayNameFor(model => model.FirstNameAr)
</th>
<th>
@Html.DisplayNameFor(model => model.MiddleNameAr)
</th>
<th>
@Html.DisplayNameFor(model => model.LastNameAr)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.FirstName)
</td>
<td>
@Html.DisplayFor(modelItem => item.MiddleName)
</td>
<td>
@Html.DisplayFor(modelItem => item.LastName)
</td>
<td>
@Html.DisplayFor(modelItem => item.FirstNameAr)
</td>
<td>
@Html.DisplayFor(modelItem => item.MiddleNameAr)
</td>
<td>
@Html.DisplayFor(modelItem => item.LastNameAr)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
</td>
</tr>
}
</table>
エラー
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /User/Student/Create
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1055.0
作成と呼ばれるビューがありますか? –
問題は、 'POST'メソッドを' GET'しようとしていることです。あなたはCreateと呼ばれる '[HttpPost]'アクションを持っています - これはあなたが学生を作るためにPOSTするものです。また、ユーザ入力のためのフォームである '[HttpGet]' Createメソッドが必要です。 – markpsmith
@PaulKaram、はい私はCreateと呼ばれるビューを持っています – Shax