Bit note (b): Use JS object to upload the value to the background

Source: Internet
Author: User

Remember the previous just wrote the value of ASP. NET from the front desk is var data=a,b,c,d,e; Loop to add a comma separated from the background also to be tested only input, it is wrong haha. Later, using a similar symbol is not a permanent ...

Now with the MVC, form add, on each input to write the corresponding model of the name, to the background directly model point properties on the line.

However, you will still encounter the submission is not a form, similar to submit exam answers, after-class evaluation, a large string of strings. See JS object in front of a bright!!! On the Code

Html:

<ul>

<li class= ' id ' >1</li>

<li class= ' name ' >A</li>

</ul>

<ul>

<li class= ' id ' >2</li>

<li class= ' name ' >B</li>

</ul>

--------------------------------------------------------------------------------

I would have written 1,a.2,b to the backstage if I had changed it. It's not the same now.

var orgarray={};//first declares a global array

$ (UL). each (function () {

var organ={

id=$ (This). Children (Li:eq (0)). HTML (),

name=$ (This). Children (Li:eq (1)). HTML ()

}

Orgarray.push (Organ); Equals List Collection

})

$.post ("url", {orgarray: json.stringify(orgarray)//Convert to String}, function (data) {})

If you pass a lot of string level, you can also set a few more Var arry={};

----------------------------------------------------------------------------------------------

Background

var Orgarray = request.form["Orgarray"];
Dynamic Orglist = Newtonsoft.Json.JsonConvert.DeserializeObject(Orgarray);

for (int i = 0; i < Orglist.count; i++)

{

Id=orglist[i].id;

Name=orglist[i].name;

Add to

}

-------------------------------------------------------------------------------------------

In this way with the previous comma stitching comparison, personally think 1: conducive to future maintenance! Directly know the meaning of the property, the province in the front desk to check, concise, convenient. 2: Avoid separating with special symbols, some errors occur. 3: Conforms to C # object-oriented

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.