多表单提交

控制器代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Mvc1.Models;

namespace Mvc1.Controllers
{
    public class HomeController : Controller
    {public ActionResult Other1()
        {
            return View();
        }

        public ActionResult FFF(string one, string two)
        {
            int end = Convert.ToInt32(one) + Convert.ToInt32(two);

            Session["end"] = end;

            return RedirectToAction("Other1");
        }

        public ActionResult GGG(string one, string two)
        {
            int end = Convert.ToInt32(one) - Convert.ToInt32(two);

            Session["end"] = end;

            return RedirectToAction("Other1");
        }
    }
}

界面代码:

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Other1</title>
</head>
<body>
    <div>
        <form id="form1" name="form1" method="post" action="FFF">
            <input type="text" name="one" />
            <input type="text" name="two" />
            <br />
            <input type="button" value="" name="btn1" onclick="form1.submit()" />
            <input type="button" value="" name="btn1" id="jian" />
        </form>
        @{
            if (Session["end"] != null)
            {
            <span>@Session["end"].ToString()</span>
                Session["end"] = null;
            }
        }
    </div>
</body>
</html>
<script type="text/javascript">
    document.getElementById('jian').onclick = function () {
        document.getElementById('form1').action = "GGG";
        form1.submit();
    };

</script>

 

posted @ 2016-09-01 10:19  露西&哈特菲利亚  阅读(128)  评论(0编辑  收藏  举报