使用MVC框架中要注意的问题(四):ActionLink只是执行Get的操作
来源:互联网 发布:手机精美时钟软件 编辑:程序博客网 时间:2024/06/06 16:30
ActionLink是产生一个链接字符串,它仅仅支持GET的Action
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage>" %><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中的代码
/// /// 将某个照片从下载列表中移除 /// /// /// //[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"); }
.csharpcode, .csharpcode pre{font-size: small;color: black;font-family: consolas, "Courier New", courier, monospace;background-color: #ffffff;/*white-space: pre;*/}.csharpcode pre { margin: 0em; }.csharpcode .rem { color: #008000; }.csharpcode .kwrd { color: #0000ff; }.csharpcode .str { color: #006080; }.csharpcode .op { color: #0000c0; }.csharpcode .preproc { color: #cc6633; }.csharpcode .asp { background-color: #ffff00; }.csharpcode .html { color: #800000; }.csharpcode .attr { color: #ff0000; }.csharpcode .alt {background-color: #f4f4f4;width: 100%;margin: 0em;}.csharpcode .lnum { color: #606060; }
.csharpcode, .csharpcode pre{font-size: small;color: black;font-family: consolas, "Courier New", courier, monospace;background-color: #ffffff;/*white-space: pre;*/}.csharpcode pre { margin: 0em; }.csharpcode .rem { color: #008000; }.csharpcode .kwrd { color: #0000ff; }.csharpcode .str { color: #006080; }.csharpcode .op { color: #0000c0; }.csharpcode .preproc { color: #cc6633; }.csharpcode .asp { background-color: #ffff00; }.csharpcode .html { color: #800000; }.csharpcode .attr { color: #ff0000; }.csharpcode .alt {background-color: #f4f4f4;width: 100%;margin: 0em;}.csharpcode .lnum { color: #606060; }