ASP.NET MVC 搜尋+儲存搜尋結果.2個按鈕共用一個表單

來源:互聯網
上載者:User

標籤:public   stat   created   utf8   ima   mod   一個   asp   var   

想要實現的效果,1.搜尋功能 2.搜尋結果儲存到text功能

前台代碼

一個表單2個按鈕,通過JS代碼來修改form的action,來實現調用不同的後台代碼

            <form name="form1"  action="~/Card/List" method="get" >                <span class="label label-success">卡號:</span>                <input class="form-inline" type="text" name="CardNum" placeholder="請輸入要查詢的卡號" value="@Request.QueryString["CardNum"]" style="width:260px" />                <span class="label label-success">面值:</span>                <input type="text" name="Price" placeholder="" value="@Request.QueryString["Price"]" style="width:100px" />                <span class="label label-success">狀態:</span>                <select name="Status">                    <option value="2" @(Request.QueryString["Status"] == "2" ? "selected=‘selected‘" : "")> 全部 </option>                    <option value="-1" @(Request.QueryString["Status"] == "-1" ? "selected=‘selected‘" : "")> 凍結 </option>                    <option value="0" @(Request.QueryString["Status"] == "0" ? "selected=‘selected‘" : "")> 已用 </option>                    <option value="1" @(Request.QueryString["Status"] == "1" ? "selected=‘selected‘" : "")> 未用 </option>                </select>                <span class="label label-success">建立日期:</span> <input type="date" class="inline laydate-icon" name="CreateDateTime" value="@Request.QueryString["CreateDateTime"]" />                <button type="submit" class="btn btn-success" onclick="mysearch()">查詢</button>                <button id="SaveText" class="btn btn-success" onclick="myexport()">匯出查詢結果</button>            </form>

JS代碼

        function mysearch() {            document.form1.action = "/Card/List";        }        function myexport() {            document.form1.action = "/Card/Export";        }

後台代碼

後台用到了mvcpager分頁,用的htmlget方式

        [CheckLogin]        [HttpGet]        public ActionResult List(string cardnum, decimal? Price, int? Status, DateTime? CreateDateTime, int id = 1)        {            return list(cardnum, Price, Status, CreateDateTime, id);        }        [CheckLogin]        [HttpGet]        public ActionResult Export(string cardnum, decimal? Price, int? Status, DateTime? CreateDateTime, int id = 1)        {            CardService cardS = new CardService();            var model = cardS.Search2(cardnum, Price, Status, CreateDateTime);            var items= list(cardnum, Price, Status, CreateDateTime, id);            string str = string.Empty;            foreach (var item in model)            {                str = str + item.CardNum+"----"+item.Price+"----"+item.CreateDateTime+"----"+item.Status + "\r\n";            }            byte[] data = Encoding.UTF8.GetBytes(str);            return File(data, "text/plain", "卡密.txt");        }        private ActionResult list(string cardnum, decimal? Price, int? Status, DateTime? CreateDateTime,int id = 1)        {            CardService cardS = new CardService();            var model = cardS.Search2(cardnum, Price, Status, CreateDateTime);            PagedList<CardDTO> InfoPager = model.ToPagedList(id, 10);            InfoPager.TotalItemCount = model.Count();            InfoPager.CurrentPageIndex = id;            CardSearchDTO model2 = new CardSearchDTO();            model2.Cards = InfoPager;            if (Request.IsAjaxRequest())                    return PartialView("_AjaxSearchGet", model2);                return View("List",model2);                    }

 

ASP.NET MVC 搜尋+儲存搜尋結果.2個按鈕共用一個表單

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.