ActionLink是产生一个链接字符串,它仅仅支持GET的Action
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<Web.Models.PhotoListItem>>" %> <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> 下载中心 </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <%if (Model != null) {%> <% using (Html.BeginForm()) { %> <h2> 下载列表</h2> 通过付费购买某些照片,我们会为你打包下载。你可以在浏览图片的时候,将它们添加到下载框<br /> <table> <tr> <th> <input type="checkbox" id="ToggleSelect" /> </th> <th> 标题 </th> <th> 编号 </th> <th> 操作 </th> </tr> <% foreach (var item in Model) { %> <tr> <td> <input type="checkbox" /> </td> <td> <%= Html.Encode(item.Title)%> </td> <td> <%= Html.Encode(item.Path)%> </td> <td>
<%= Html.ActionLink("删除", "DeleteFromDownloadList", new { id = item.Path })%>
</td> </tr> <% } %> </table> <input type="hidden" id="FileList" name="FileList" value="" /> <br /> <input type="submit" value="下载" id="download" /> <% } %> <% } else { %> 对不起,你目前没有任何下载的列表 <% } %> </asp:Content> <asp:Content ID="Content3" ContentPlaceHolderID="head" runat="server"> <script src="../../js/private/DownloadPage.js" type="text/javascript"></script> </asp:Content>
Controller中的代码
/// <summary> /// 将某个照片从下载列表中移除 /// </summary> /// <param name="id"></param> /// <returns></returns> //[AcceptVerbs(HttpVerbs.Post)] [Authorize] public ActionResult DeleteFromDownloadList(string id) { string profileKey = "DownloadList"; ProfileBase profile = ProfileBase.Create(User.Identity.Name); Models.DownloadList list = profile.GetPropertyValue(profileKey) as Models.DownloadList; if (list != null && list.Items != null) { list.Items.Remove(list.Items.FirstOrDefault(i => i.Path.Equals(id))); profile.Save(); } return RedirectToAction("Download"); }