zoukankan      html  css  js  c++  java
  • 使用MVC框架中要注意的问题(四):ActionLink只是执行Get的操作

    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");
    
            }
     
  • 相关阅读:
    LeetCode 116. 填充每个节点的下一个右侧节点指针
    angluar 表单的验证 动态数据项表单验证
    Angular:ng-style,ng-class的使用
    1.splice(),slice(),split()快查
    js输入小写金额转大写
    Angular--CheckBox,checkbox多选,保存的时候用逗号隔开
    Angular--CheckBox
    Angular--Radio
    对于mysql中的group by分组后获取组内创建时间最大的那行数据
    GIT版本管理看这一篇就够了
  • 原文地址:https://www.cnblogs.com/chenxizhang/p/1634726.html
Copyright © 2011-2022 走看看