zoukankan      html  css  js  c++  java
  • MVC的多表单

    中心思想就是在一个表单内不规定”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

    完!!

  • 相关阅读:
    逻辑回归和最大熵模型
    R文本挖掘之jiebaR包
    iOS 好文源码收藏
    学习iOS最权威的网站
    面向对象的六大原则
    Dart的JIT 与 AOT
    iOS组件化开发-发布私有库
    Flutter 基础布局Widgets之Align
    Flutter报错 Waiting for another flutter command to release the startup lock...
    Dart中类的getter和setter
  • 原文地址:https://www.cnblogs.com/wwz-wwz/p/6137098.html
Copyright © 2011-2022 走看看