@model IEnumerable<Library.Web.Models.Book> @{ ViewBag.Title = "Index"; Layout = "~/Views/Shared/_Layout.cshtml"; } <h2>Index</h2> <p> @Html.ActionLink("创建新书", "Create") </p> <table> <tr> <th> @Html.DisplayNameFor(model => model.Title) </th> <th> @Html.DisplayNameFor(model => model.Foreword) </th> <th> @Html.DisplayNameFor(model => model.Pages) </th> <th> @Html.DisplayNameFor(model => model.Author) </th> <th></th> </tr> @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.Title) </td> <td> @Html.DisplayFor(modelItem => item.Foreword) </td> <td> @Html.DisplayFor(modelItem => item.Pages) </td> <td> @Html.DisplayFor(modelItem => item.Author) </td> <td> @Html.ActionLink("编辑", "Edit", new { id=item.Id }) | @Html.ActionLink("详细", "Details", new { id=item.Id }) | @Html.ActionLink("删除", "Delete", new { id=item.Id }) </td> </tr> } </table>
Edit.cshtml:
@model Library.Web.Models.Book @{ ViewBag.Title = "Edit"; Layout = "~/Views/Shared/_Layout.cshtml"; } <h2>Edit</h2> @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div> <h4>Book</h4> <hr /> @Html.ValidationSummary(true) @Html.HiddenFor(model => model.Id) <div> @Html.LabelFor(model => model.Title, new { @class = "control-label col-md-2" }) <div> @Html.EditorFor(model => model.Title) @Html.ValidationMessageFor(model => model.Title) </div> </div> <div> @Html.LabelFor(model => model.Foreword, new { @class = "control-label col-md-2" }) <div> @Html.TextAreaFor(model => model.Foreword) @Html.ValidationMessageFor(model => model.Foreword) </div> </div> <div> @Html.LabelFor(model => model.Pages, new { @class = "control-label col-md-2" }) <div> @Html.EditorFor(model => model.Pages) @Html.ValidationMessageFor(model => model.Pages) </div> </div> <div> @Html.LabelFor(model => model.Author, new { @class = "control-label col-md-2" }) <div> @Html.EditorFor(model => model.Author) @Html.ValidationMessageFor(model => model.Author) </div> </div> <div> <div> <input type="submit" value="Save" /> </div> </div> </div> } <div> @Html.ActionLink("返回列表", "Index") </div> @section Scripts { @Scripts.Render("~/bundles/jqueryval") }
Details.cshtml:
@model Library.Web.Models.Book @{ ViewBag.Title = "Details"; Layout = "~/Views/Shared/_Layout.cshtml"; } <h2>Details</h2> <div> <h4>Book</h4> <hr /> <dl> <dt> @Html.DisplayNameFor(model => model.Title) </dt> <dd> @Html.DisplayFor(model => model.Title) </dd> <dt> @Html.DisplayNameFor(model => model.Foreword) </dt> <dd> @Html.DisplayFor(model => model.Foreword) </dd> <dt> @Html.DisplayNameFor(model => model.Pages) </dt> <dd> @Html.DisplayFor(model => model.Pages) </dd> <dt> @Html.DisplayNameFor(model => model.Author) </dt> <dd> @Html.DisplayFor(model => model.Author) </dd> </dl> </div> <p> @Html.ActionLink("编辑", "Edit", new { id = Model.Id }) | @Html.ActionLink("返回列表", "Index") </p>
Delete.cshtml:
@model Library.Web.Models.Book @{ ViewBag.Title = "Delete"; Layout = "~/Views/Shared/_Layout.cshtml"; } <h2>Delete</h2> <h3>Are you sure you want to delete this?</h3> <div> <h4>Book</h4> <hr /> <dl> <dt> @Html.DisplayNameFor(model => model.Title) </dt> <dd> @Html.DisplayFor(model => model.Title) </dd> <dt> @Html.DisplayNameFor(model => model.Foreword) </dt> <dd> @Html.DisplayFor(model => model.Foreword) </dd> <dt> @Html.DisplayNameFor(model => model.Pages) </dt> <dd> @Html.DisplayFor(model => model.Pages) </dd> <dt> @Html.DisplayNameFor(model => model.Author) </dt> <dd> @Html.DisplayFor(model => model.Author) </dd> </dl> @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div> <input type="submit" value="Delete" /> | @Html.ActionLink("返回列表", "Index") </div> } </div>
Create.cshtml: