MVC 提交方法

MVC 使用Jquery实现AJax

<script type="text/javascript">
    function GetTime() {
        $.get("Home/GetTime", function (response) {
            $("#myPnl").html(response);
        });

        return false;
    }
</script>
<div id="myPnl" style="width: 300px; height: 30px; border: 1px dotted silver;">
</div>
<a href="#" onclick="return GetTime();">Click Me</a>

public ActionResult GetTime()
{
    return Content(DateTime.Now.ToString());
}

 //删除
    function DeleteAll(id) {
        //if ($(":checkbox[name=‘checkbox_app‘]:checked").size() == 0) {
        //    alert("您没有选择要删除的数据!"); return;
        //}
        if (!confirm(‘您真的要删除所选应用吗?‘)) {
            return false;
        }
        //var id = "";
        //var box = "";
        //$("input[name=‘checkbox_app‘]:checked").each(function () {
        //    box = $(this);
        //    id = box.val();
        //});
        $.ajax({
            url: "/Home/DeleteIWFAll/" + id,
            type: "post",
            success: function (data) {
                if (data.success == true) {
                    //box.parent().remove();
                    alert("删除成功!");
                    reloadiframe("tab_" + appid.replace("-", "") + "_iframe");
                    $("#searchform").submit();
                }
                else {
                    alert("删除成功失败!")
                    return false;
                }

            },
            error: function (err) {
                alert("删除成功失败!")
                return false;
            }
        });

 public JsonResult DeleteIWFAll(string id)
        {
            JsonResult json = new JsonResult();
            //调用删除方法
            int count = PC_InnovationPointBLL.DeleteIWFAll(id);
            if (count > 0)
            {
                json.Data = new { success = true };
            }
            else
            {
                json.Data = new { success = false };
            }
            return json;
        }    function Filter() {        $("#isSearch").val("true");        $("#searchform").attr("action", "/Home/[email protected](ViewBag.Query)&AppName=" + AppName + "&tabid=" + ‘@ViewBag.tabid‘ + "&flowname=" + flowname);        $("#searchform").submit();    }

document.onkeydown = function (event) {         var e = event || window.event || arguments.callee.caller.arguments[0];         if (e && e.keyCode == 13) { // enter 键             //要做的事情             $("#isSearch").val("true");             $("#searchform").attr("action", "/Home/[email protected](ViewBag.Query)&AppName=" + AppName + "&tabid" + ‘@ViewBag.tabid‘ + "&flowname=" + flowname);

$(‘#searchform‘).submit();         }     }

通过post方法实现FormAjax提交

<script type="text/javascript">
    $(function () {
        $("#Button1").click(function () {
            //验证内容
            if ($("#Menutype").val() == ‘‘) {
                 alert("所属类型不能为空");
                return false;
            }
            if ($("#MenuName").val() == "")
            {
                alert("菜单名称不能为空");
                return false;
            }
            //提交
            $("#mainForm").submit();
        });
    });
</script>
<form action="/Home/Index" method="post" id="mainForm">
 <table id="MemberArea">
            <thead>
                 <tr>
                    <td colspan="2">
                        <h3>
                            新增菜单</h3>
                    </td>
                </tr>               

            </thead>
            <tbody>
                <tr>
                    <td>
                        所属类型
                    </td>
                    <td>
                        @Html.TextBox("Menutype")
                    </td>
                </tr>
                <tr>
                    <td>
                        菜单名称
                    </td>
                    <td>
                        @Html.TextBox("MenuName")
                    </td>
                </tr>
                <tr>
                    <td>
                        连接地址
                    </td>
                    <td>
                        @Html.TextBox("URL")
                    </td>
                </tr>

                 <tr>
                    <td>目标框架</td>
                    <td> @Html.TextBox("TarGetFrame")</td>
                </tr>
                 <tr>
                    <td> 图标名称</td>
                    <td> @Html.TextBox("ICON")</td>
                </tr>
                 <tr>
                    <td>权限名称</td>
                    <td> @Html.TextBox("PerMIssionName")</td>
                </tr>
                 <tr>
                    <td>权限表示</td>
                      <td> @Html.TextBox("PerMIssionId")</td>
                </tr>
                <tr>
                    <td>类型排序</td>
                   <td> @Html.TextBox("Orders")</td>
                </tr>  

                  <tr>
                    <td>说名</td>
                    <td>@Html.TextBox("DescriptIon")</td>
                </tr> 

                <tr>
                    <td colspan="2">
                        <input type="button" id="Button1" value="Index" />
</td>
                </tr>
            </tbody>
        </table>
</form>
Controllers
[HttpPost]
        public ActionResult Index(Maticsoft.Model.Menu model)
        {
           //SelectList selectNameList = new SelectList("123");//构造一个下拉列表的键值对
             //ViewData["Menutype"] = selectNameList;
               model.id=model.id +=1;
                menu.Add(model);
               // ViewData["Message"] = "添加成功!";
                return View(model);
        }
时间: 2024-07-29 22:22:45

MVC 提交方法的相关文章

Mvc 提交表单的4种方法全程详解

一,MVC  HtmlHelper方法 Html.BeginForm(actionName,controllerName,method,htmlAttributes){} BeginRouteForm 方法 (HtmlHelper, String, Object, FormMethod) 二,传统Form表单Aciton属性提交 三,Jquery+Ajax 提交表单 四,MVC Controller控制器和表单参数传递 MVC  HtmlHelper方法 一,Html.BeginForm(act

spring mvc 控制器方法传数组对象的一些经验

因为项目需要在一个表单里面提交多个对象,比较好的做法就是直接在控制器方法参数里传一个数组. 由于Spring mvc框架在反射生成控制方法的参数对象的时候会调用这个类的getDeclaredConstructor方法来获得构造函数, 但是一直报NoSuchMethodException的异常. 根据这个方法的jdk文档,这个类是一个数组对象时,这个方法会抛出java.lang.NoSuchMethodException,因为接口.数组类.void.基本类型没有构造函数. 同事后来给我支了两招,使

ASP.NET MVC提交一个较复杂对象至WCF Service

前一篇<jQuery.Ajax()执行WCF Service的方法>http://www.cnblogs.com/insus/p/3727875.html 我们有练习在asp.net mvc应用程序中,POST 数据去wcf service并执行方法.本篇的练习是提交较复对象至wcf service执行方法.前一篇中,它只传递两个参数.如果我们平时开发,需要传递过多的参数时,那得需要写很多个参数.因此产生此篇,把较多个参数,创建为一个对象.然后只传递这个对象至wcf service即可. 下面

【Struts2】★☆之struts2对Action提交方法进行验证

[Struts2]★☆之struts2对Action提交方法进行验证 在实际的开发项目中,我们通常采用的是js对我们输入的值进行验证,例如,用户名的长度,密码长度,等等.但是这样做,不好之处就是我们可以通过人为的将开发者的验证js注掉,这样就导致验证失败,对后台安全性是一个很大的威胁,在采用struts2进行开发时,我们可以采用框架内置的校验器,对我们的Action进行校验.本文所讲诉的就是如何使用重写struts2中的ActionSupport里面的validate方法对输入值进行校验. ok

jQuery的ajax的form提交方法应用

1.如果不用ajax的form提交,就必须把表单的每一条数据进行获取,并提交给action进行处理.这样做比较麻烦,现在用了jQuery的easyui,使用封装好的ajax的form提交.脚本代码如下: //提交表单 function sysusersave(){ if($.formValidator.pageIsValid()){//校验表单输入信息是否合法 //使用jquery的ajax from提交,指定from的id和回调方法,提交的url使用提from中的action,参数为空,传递J

Castle IOC FOR MVC 使用方法

Castle Web.API 使用方法 一.创建 WindsorActivator 继承 IHttpControllerActivator public class WindsorActivator :IHttpControllerActivator { private readonly IWindsorContainer container; public WindsorActivator(IWindsorContainer container) { this.container = cont

MVC提交时验证

第一种 @using (Html.BeginForm("ProdPromotionEdit", "Product", FormMethod.Post, new { onsubmit = "return check()" })) 第二种 <input onsubmit="return check() " type="submit"> 第三种jquery $("#xxxform"

不同编码页面之间表单的提交方法

关键词:编码 表单 GB2312 POST UTF8 使用accept-charset 属性 accept-charset 属性规定服务器处理表单数据所接受的字符集.accept-charset 属性允许您指定一系列字符集,服务器必须支持这些字符集,从而得以正确解释表单中的数据.该属性的值是用引号包含字符集名称列表.如果可接受字符集与用户所使用的字符即不相匹配的话,浏览器可以选择忽略表单或是将该表单区别对待.此属性的默认值是 "unknown",表示表单的字符集与包含表单的文档的字符集

silverlight调用MVC WebApi方法

1.创建ASP.NET MVC4 Web应用程序,选择WebAPI模板 2.添加silverlight项目 3.新建一个数据模型类,代码如下: using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace NetMVCAPI.Models { public class Contact { public int Id { get; set; } public string