我对 MVC 很陌生,我正在查看 NerdDinner 的代码
看法:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<NerdDinner.Models.Dinner>" %>
<asp:Content ID="Title" ContentPlaceHolderID="TitleContent" runat="server">
Delete Confirmation: <%:Model.Title %>
</asp:Content>
<asp:Content ID="Main" ContentPlaceHolderID="MainContent" runat="server">
<h2>
Delete Confirmation
</h2>
<div>
<p>Please confirm you want to cancel the dinner titled:
<i> <%:Model.Title %>? </i> </p>
</div>
<% using (Html.BeginForm()) { %>
<input name="confirmButton" type="submit" value="Delete" />
<% } %>
</asp:Content>
控制器:
[HttpPost, Authorize]
public ActionResult Delete(int id, string confirmButton) {
Dinner dinner = dinnerRepository.GetDinner(id);
if (dinner == null)
return View("NotFound");
if (!dinner.IsHostedBy(User.Identity.Name))
return View("InvalidOwner");
dinnerRepository.Delete(dinner);
dinnerRepository.Save();
return View("Deleted");
}
控制器如何获取要删除的项目的 ID?视图上似乎没有任何内容包含要传递给控制器的 ID。