Previously, I used AJax to pass parameters to the Controller, and then called the server-side method to make changes to the database. Today I encountered a new method, which is form submission, which can save the need for AJax to pass parameters.
After the form is submitted, we can get the value in the control on the form, and then call the server-side method to make changes to the database. The screenshot below is a specific business requirement.
1. Function to be implemented: From the above form, get the value in the control and then pass it to the background. Below is the form code.
2. Form code
<div id="Editwin" class="easyui-window" title="编辑班级信息" style="width: 400px; height: auto;top:105px" data-options="closed:true,collapsible:false,minimizable:false,maximizable:false"> <div style="margin-top: 30px; margin-bottom: 30px; margin-left: 70px;"> <form id="EditForm" method="post"> <table> <tr> <td>班级名称:</td> <td> <input class="easyui-validatebox" type="text" id="EditClassName" name="ClassName" data-options="required:true,validType:['maxLength[20]']"/> </td> </tr> <tr> <td> <input style="display:none" class="easyui-textbox" type="text" id="EditClassID" name="ClassID" data-options="required:true"/> </td> </tr> <tr> <td>所属机构:</td> <td> <input id="EditOrganizationID" class="easyui-combobox" name="OrganizationName1" data-options="required:true"/> </tr> <tr> <td>年级:</td> <td> <input id="EditGradeID" class="easyui-combobox" name="GradeName" data-options="required:true"/> </tr> <tr> <td>备注:</td> <td> <textarea class="easyui-validatebox" id="NoteId" name="Note" validType:['maxLength[50]></textarea> </tr> </table> <div style="margin-top: 20px;"> <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" style="margin-left: 10px;" onclick="EditsubmitForm()">确定</a> <a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" style="margin-left: 60px;" onclick="EditclearForm()">取消</a> </div> </form> </div> </div>
3. Form submission code
function EditsubmitForm() { $('#EditForm').form('submit', { url: "/BasicClass/ModifyClassInfo", onSubmit: function () { //表单提交前的回调函数 var isValid = $(this).form('validate');//验证表单中的一些控件的值是否填写正确,比如某些文本框中的内容必须是数字 if (!isValid) { } return isValid; // 如果验证不通过,返回false终止表单提交 }, success: function (data) { //表单提交成功后的回调函数,里面参数data是我们调用/BasicClass/ModifyClassInfo方法的返回值。 if (data > 0) { $.messager.show({ title: '提示消息', msg: '提交成功', showType: 'show', timeout: 1000, style: { right: '', bottom: '' } }); $('#dg').datagrid('reload'); // 重新载入当前页面数据 $('#Editwin').window('close'); //关闭窗口 } else { $.messager.alert('提示信息', '提交失败,请联系管理员!', 'warning'); } } }); }
4. The background Controller obtains the data in the form
//获得要添加的班级的名称 string ClassName = Request.Form["ClassName"]; //获得班级ID Guid ClassID = new Guid(Request.Params["ClassID"]); string ClassNote = Request.Form["Note"];
After first practice, I feel that it is much easier to use than AJax passing parameters, because AJax needs to write all the names of each parameter when passing parameters, and when the form is submitted, all the contents in the form will be sent by default, so that in the form As long as there is any data, we can get it in the background. Of course, these data are bound in advance, or we have filled them in before.
The above is the entire content of this article. I hope it will be helpful to everyone in learning jquery programming.

easyui是jquery插件。easyui是基于JQuery的一个前台ui界面的插件,用于帮助web开发者更轻松的打造出功能丰富并且美观的UI界面。easyui是个完美支持HTML5网页的框架,可以帮助开发者节省网页开发的时间和规模。

PHP表单处理:表单数据查询与筛选引言在Web开发中,表单是一种重要的交互方式,用户可以通过表单向服务器提交数据并进行进一步的处理。本文将介绍如何使用PHP处理表单数据的查询与筛选功能。表单的设计与提交首先,我们需要设计一个包含查询与筛选功能的表单。常见的表单元素包括输入框、下拉列表、单选框、复选框等,根据具体需求进行设计。用户在提交表单时,会将数据以POS

Java实现表单的实时验证与提示功能随着网络应用的普及和发展,表单的使用也变得越来越重要。表单是网页中用于收集和提交用户数据的元素,例如注册或登录页面的表单。在用户填写表单时,经常需要对其输入的数据进行验证和提示,以保证数据的正确性和完整性。在本文中,我们将介绍如何使用Java语言实现表单的实时验证与提示功能。HTML表单的搭建首先,我们需要使用HTML语言

Nette框架是一款用于PHPWeb开发的轻量级框架,以其简单易用、高效稳定的特点受到了广泛的欢迎和使用。在开发Web应用时,使用表单和验证是不可避免的需求。本文将介绍如何在Nette框架中使用表单和验证。一、表单构建在Nette框架中,表单可以通过Form类来创建。Form类在NetteForms命名空间中,可以通过use关键字引入。useNetteF

在Web开发中,表单是用户和服务器之间沟通的重要渠道。为确保安全,我们需要在表单提交时添加Token验证机制来避免恶意攻击者的进攻。Token验证的基本原理是:服务器生成随机数,在表单中添加隐藏域的方式将Token传递给客户端,客户端提交表单时将Token发送回服务器,服务器验证Token的正确性,如果匹配,则允许表单提交,否则拒绝提交。下面我们将介绍在PH

如何优化Vue开发中的表单自动填充问题随着Vue框架的不断发展和应用,越来越多的开发者选择使用Vue来开发前端应用。在Vue开发过程中,表单是一个非常常见的组件,而表单自动填充问题也是开发者经常会遇到的一个问题。本文将介绍如何优化Vue开发中的表单自动填充问题,以提高用户体验。表单自动填充问题指的是当用户在表单中输入某些信息后,关闭浏览器再重新打开时,浏览器

BinaryX的代币更名:从BNX到FOUR,再到FORM,战略调整背后的深层含义BinaryX近期将代币符号从$FOUR更改为$FORM,引发业界广泛关注。这并非BinaryX首次更名,其代币符号曾经历BNX到FOUR的转变。本文将深入探讨这一系列更名背后的战略意图。一、代币更名历程与战略考量BinaryX最初于2021年推出基于BNB链的$BNX代币,用于支持其Play-to-Earn(P2E)游戏生态。2024年初,为优化经济模型,BinaryX对$BNX进行了分割,并逐渐拓展至GameF

表单传送数据到php乱码的解决办法:1、在html中的head处添加“<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">”;2、确保所有文件都是utf8编码;3、在php中添加“header("Content-Type:text/html; charset=UTF-8");”。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version
SublimeText3 Linux latest version

Notepad++7.3.1
Easy-to-use and free code editor

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6
Visual web development tools
