MVC的多表單

來源:互聯網
上載者:User

標籤:ted   play   傳值   public   click   isp   set   技術分享   方法   

中心思想就是在一個表單內不規定”action“,在js裡面用@Url.Axtion("視圖層","控制器")方法來設定表單的傳值。

 

 

控制器

   public ActionResult Jia(string a1, string a2)        {            int end = Convert.ToInt32(a1) + Convert.ToInt32(a2);            TempData["a1"] = a1;            TempData["a2"] = a2;            TempData["Jia"] = end;            return RedirectToAction("Other1","Home");        }        public ActionResult Jian(string a1, string a2)        {            int end = Convert.ToInt32(a1) - Convert.ToInt32(a2);            TempData["a1"] = a1;            TempData["a2"] = a2;            TempData["Jia"] = end;            return RedirectToAction("Other1", "Home");        }
View Code

 

 

 

視圖層

@{    Layout = null;}<!DOCTYPE html><html><head>    <meta name="viewport" content="width=device-width" />    <title>Other1</title>    <script src="~/js/jquery-1.7.2.min.js"></script></head><body>    <div>        <form method="post">            <input type="text" name="a1" value="@TempData["a1"]" />            <input type="text" name="a2" value="@TempData["a2"]" />=                        <input type="text" name="a3" value="@TempData["Jia"]" />            <input type="button" id="btn_jia" value="加法計算" />            <input type="button" id="btn_jian" value="減法計算" />        </form>        <script type="text/javascript">            document.getElementById("btn_jia").onclick = function () {                this.form.setAttribute("action", "@Url.Action("Jia", "Home")");                this.form.submit();            };            document.getElementById("btn_jian").onclick = function () {                this.form.setAttribute("action", "@Url.Action("Jian", "Home")");                this.form.submit();            };        </script>    </div></body></html>
View Code

完!!

MVC的多表單

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.