ASP. net mvc uses the EasyUI datagrid to submit and save multiple options.

Source: Internet
Author: User

To add the datagrid component of EasyUI to the select checkbox column, and submit the batch addition function in the background, the page code is as follows: Copy codeThe Code is as follows: <script language = "javascript" type = "text/javascript">
$ (Function (){
// Searchbox
$ ('# Selectgoods-keywords'). searchbox ({
Searcher: function (val, name ){
SearchInfo (val );
}
});
// Datagrid
$ ('# Selectgoods-grid'). datagrid ({
Url: '/Goods/list ',
PageNumber: 1,
PageSize: 20,
PageList: [20, 40, 60, 80,100]
});
// Form
});
Function searchInfo (val ){
// Var keytype = $ ('# keytype'). combobox ('getvalue ');
Var keytype = 'goods _ name ';
Var keywords = val;
$ ('# Selectgoods-grid'). datagrid ('reload', {keytype: keytype, keywords: keywords });
}
Function saveSelectGoods (){
Var ids = [];
Var rows = $ ('# selectgoods-grid'). datagrid ('getselections ');
For (var I = 0; I <rows. length; I ++ ){
Ids. push (rows [I]. Identifier );
}
Var selectsupplier = '<% = ViewData ["supplier"] %> ';
$. Post ('/SupplierGoods/SaveSelect', {supplier: selectsupplier, checks: ids. join (',')}, function (data ){
If (data ){
$ ('# Goodslist-grid'). datagrid ('reload ');
$ ('# GoodsInfo-window'). window ('close ');
} Else {
Alert ('failed to save! ');
}
}, 'Json ');
}
</Script>
<Div style = "width: 100%; height: 100%">
<Table id = "selectgoods-grid" class = "easyui-datagrid" fit = "true" toolbar = "# tlb_selectgoods_search" pagination = "true"
Rownumbers = "true" fitColumns = "true" idField = "Identifier">
<Thead>
<Tr>
<Th field = "ck" checkbox = "true"> </th>
<Th field = "Identifier" hidden = "true" width = "0" editor = "text"> Id </th>
<Th field = "Goods_Name" width = "100" editor = "{type: 'validatebox', options: {required: true}"> item name </th>
<Th field = "Chemistry" width = "100" editor = "{type: 'validatebox', options: {required: true}"> chemical indicator </th>
<Th field = "Physical" width = "100" editor = "{type: 'validatebox', options: {required: true}"> Physical indicator </th>
<Th field = "Partner_Name" width = "50" editor = "{type: 'validatebox', options: {required: true}"> cooperation status </th>
</Tr>
</Thead>
</Table>
<Div id = "tlb_selectgoods_search">
Product Name: <input name = "keywords" id = "selectgoods-keywords" class = "easyui-searchbox"/> <a href = "#" class = "easyui-linkbutton" iconCls =" icon-save "plain =" true "onclick =" javascript: saveSelectGoods () "> Save </a>
</Div>
</Div>

The Controller code of ASP. net mvc is as follows:Copy codeThe Code is as follows: // <summary>
/// Add multiple items
/// </Summary>
/// <Param name = "supplier"> supplier ID </param>
/// <Returns> </returns>
Public ActionResult SelectGoods (string supplier)
{
ViewData ["supplier"] = supplier;
Return View ();
}
/// <Summary>
/// Save the product information added in batches
/// </Summary>
/// <Param name = "checks"> selected item ID </param>
/// <Param name = "supplier"> supplier name </param>
/// <Returns> </returns>
Public JsonResult SaveSelect (string checks, string supplier)
{
JsonResult result = new JsonResult ();
Result. Data = false;
Try
{
If (String. IsNullOrEmpty (supplier ))
Return result;
SupplierGoods goods = new SupplierGoods ();
Goods. Identifier = 0;
// Assemble xml
String ids = Communion. StringHelper. BuildXmlID (checks );
Goods. Goods_ID =-1; // indicates batch insert
Goods. Note = ids;
Goods. Month_Output = Convert. ToDouble (String. IsNullOrEmpty (this. ReadFromRequest ("Month_Output "))? "0": this. ReadFromRequest ("Month_Output "));
Goods. Supplier_ID = Convert. ToInt32 (supplier );
Goods. Create_Date = DateTime. Now;
Goods. Customers = this. ReadFromRequest ("Customers ");
Goods. Equipment = this. ReadFromRequest ("Equipment ");
Goods. Detail_Params = this. ReadFromRequest ("Detail_Params ");
Goods. IsDefault = Convert. ToInt32 (String. IsNullOrEmpty (this. ReadFromRequest ("IsDefault "))? "0": this. ReadFromRequest ("IsDefault "));
Business business = new BusinessLogic ();
Int id = business. Save <SupplierGoods> (goods );
If (goods. Identifier = 0)
{
Goods. Identifier = id;
}
Result. Data = true;
Return result;
}
Catch (Exception e)
{
Return result;
}
}

The stored procedure uses xml variables to batch add and save the imported xml type ID sets to the database. The Stored Procedure Code is as follows:Copy codeThe Code is as follows: alter procedure [dbo]. [View_SupplierGoodsCreate]
@ Identifier int,
@ Supplier_ID int,
@ Goods_ID int,
@ IsDefault int,
@ Create_Date datetime,
@ Month_Output float (8 ),
@ Goods_Name nvarchar (400) = NULL,
@ Physical nvarchar (400) = NULL,
@ Chemistry nvarchar (400) = NULL,
@ Customers nvarchar (400) = NULL,
@ Equipment nvarchar (400) = NULL,
@ Note nvarchar (MAX) = NULL,
@ Detail_Params nvarchar (400) = NULL
AS
IF @ Goods_ID =-1
BEGIN
-- Insert items in batches
DECLARE @ xml
SET @ xml = @ Note
Insert into Supplier_Goods (Supplier_ID, Goods_ID, Create_Date, Month_Output, MERS MERs, Equipment, Note, isdefault, Detail_Params)
SELECT @ Supplier_ID, identifier, @ Create_Date, 0, null, 0, null
FROM Base_Goods
WHERE
Identifier in (Select
T. ID. value ('.', 'int') As ID
From
@ Xml. nodes ('/XML/id') as T (ID) and Identifier not in (select goods_id from Supplier_Goods where Supplier_ID = @ Supplier_ID)
SET @ Identifier = @ Goods_ID
END

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.