650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M02/08/2D/wKiom1ndOBjwnpd4AAAMkennUYc858.png-wh_500x0-wm_ 3-wmp_4-s_1559099237.png "title=" qq picture 20171010213055.png "alt=" Wkiom1ndobjwnpd4aaamkennuyc858.png-wh_50 "/>
View Code
@using (Html.BeginForm ("H", "DEFAULT1"))//DEFAULT1 Controller H is a method
{
Loop add 5 x Checkboxs
for (int i = 0; i < 5; i++)
{
<input type= "checkbox" id= "@i" name= "Checko" value= "@i"/><span>@i</span>
}
<input type= "Submit" id= "BTN" value= "Submit"/>
}
Controller code
Int[] Array types can be customized
Checko gets the value of the checked checkbox in the form of an array
Public ActionResult H (int[] Checko)
{
Define a ArrayList array for easy debugging look
ArrayList list = new ArrayList ();
foreach (var item in Checko)
{
You can write your own INSERT statement (add data)
List. ADD (item. ToString ());//This is easy to debug to see
}
Return Content ("");
}
Simulation Database
Public ActionResult F ()
{
The value of the checkbox in the View interface is a loop-added 0-4
Here you define an array to simulate the query out of the data using JQ's Ajax call today and tick based on value values
ArrayList list = new ArrayList ();
List. ADD ("1");
List. ADD ("3");
List. ADD ("0");
return Json (list);
}
$.ajax ({
Type: "Post",
URL: "/default1/f",//Controller name/method name
async:false,//Synchronous Asynchronous
success:function (data) {
var json = data;
$.each (JSON, function (I, t) {
var s = json[i];//are 1, 3, 0, respectively.
$ ("input[value=" +s+ "]"). attr ("Checked", "checked");//Check by Value
})
}
})
This article is from the "go to Daniel's direction" blog, make sure to keep this source http://949770845.blog.51cto.com/10170051/1971295
MVC selects the corresponding check box based on the value of the checkbox and gets the value of the selected value