demo
@model IEnumerable<MvcApplication4.Models.FFlow>
@{
ViewBag.Title = "Demo";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Demo</h2>
<table>
<thead>
<tr>
<th></th>
@foreach(var item in Model){
<th>@item.Name</th>
}
</tr>
</thead>
<tbody>
@foreach(var item in Model){
<tr>
<td>@item.Name</td>
<td>
<input type="checkbox" value="1" id="1"/>
</td>
<td>
<input type="checkbox" value="1" id="2"/>
</td>
<td>
<input type="checkbox" value="1" id="3"/>
</td>
<td>
<input type="checkbox" value="1" id="4"/>
</td>
</tr>
}
</tbody>
</table>
<input type="button" id="summit" value="提交" />
<script src="~/Scripts/jquery-1.7.1.js"></script>
<script type="text/javascript">
$(function () {
$("#summit").click(function () {
var items = [];
$('table > tbody').find('tr').each(function (index) {
var str = "";
$(this).find("input:checked").each(function () {
str += $(this).attr("id") +",";
});
items.push(str.substr(0,str.length-1));
});
//for (var i = 0; i < items.length; i++) {
// alert(items[i]);
//}
$.ajax({
type: 'post',
url: 'http://localhost:8493/Home/Demo',
data: { id: 2, curid: 3, param: items },
datatype:JSON,
traditional: true,
success: function (result) {
if (result.success) {
alert("hello");
}
},
error: function (xhr) {
}
});
});
});
</script>
后端:
[HttpPost]
public JsonResult Demo(int id ,int curid,string[] param)
{
bool result = true;
if (param != null && param.Length > 0)
{
try
{
for (int i = 0; i < param.Length; i++)
{
if (!String.IsNullOrEmpty(param[i].ToString()))
{
int idd = 5;
}
}
}
catch(Exception ex){
result = false;
}
}
return Json(new { success = result });
}