gpt4 book ai didi

javascript - 如何从 MVC 项目中的每个表行获取每个值?

转载 作者:行者123 更新时间:2023-12-03 11:17:03 25 4
gpt4 key购买 nike

我认为有以下网络网格:

@using (Html.BeginForm("InsertSensorsInExistingPredefineView", "PredefinedViews", FormMethod.Post))
{

@gridSensorChoose.GetHtml(
tableStyle: "webgrid3-table",
headerStyle: "webgrid3-header",
footerStyle: "webgrid3-footer",
alternatingRowStyle: "webgrid3-alternating-row",//
selectedRowStyle: "webgrid3-selected-row",
rowStyle: "webgrid3-row-style",//
mode: WebGridPagerModes.All,
columns:

gridSensorChoose.Columns(

gridSensorChoose.Column("SensorID", format: @<text> <input readonly="readonly" name="SensorID" id="SensorID" value="@item.SensorID" /> </text>, style: "col1Width"),

gridSensorChoose.Column("DeviceID", format: @<text> <span id="DeviceID">@item.DeviceID</span> </text>, style: "col1Width"),

gridSensorChoose.Column("SensorType", format: @<text> <span id="SensorType" class="SensorType">@item.SensorType</span> </text>, style: "col1Width"),

gridSensorChoose.Column("SensorName", @Html.Localize("sensorName").ToString(), format: @<text> <span><label id="SensorName">@item.SensorName</label> </span> </text>, style: "col2Width", canSort: false),

gridSensorChoose.Column("VAL", format: @<text><span class="Val"> @Html.CheckBox("val") </span></text>, style:"col1Width", canSort: false),

gridSensorChoose.Column("MIN", format: @<text><span class="Min"> @Html.CheckBox("min") </span> </text>, style: "col1Width", canSort: false),

gridSensorChoose.Column("AVG", format: @<text> <span class="Avg"> @Html.CheckBox("avg") </span> </text>, style: "col1Width", canSort: false),

gridSensorChoose.Column("MAX", format: @<text> <span class="Max"> @Html.CheckBox("max") </span> </text>, style: "col1Width", canSort: false),

gridSensorChoose.Column("SUM", format: @<text> <span class="Sum"> @Html.CheckBox("sum") </span> </text>, style: "col1Width", canSort: false),

gridSensorChoose.Column("INT", format: @<text> <span class="Int"> @Html.CheckBox("int") </span> </text>, style: "col1Width", canSort: false)

))


<input type="submit" value="@Html.Localize("save")" formaction="/PredefinedViews/InsertSensorsInExistingPredefineView" />
}

此 View 在浏览器中显示以下 html,如下所示:

<table class="webgrid3-table">
<thead>
<tr class="webgrid3-header">
<th scope="col" style="display: none;">
<a href="/PredefinedViews/CreateSensorList? selDeviceID=1&amp;sort=SensorID&amp;sortdir=ASC">SensorID</a>
</th>
<th scope="col" style="display: none;">
<a href="/PredefinedViews/CreateSensorList?selDeviceID=1&amp;sort=DeviceID&amp;sortdir=ASC">DeviceID</a>
</th>
<th scope="col" style="display: none;">
<a href="/PredefinedViews/CreateSensorList?selDeviceID=1&amp;sort=SensorType&amp;sortdir=ASC">SensorType</a>
</th>
<th scope="col">
Sensor Name
</th>
<th scope="col">
VAL
</th>
<th scope="col">
MIN
</th>
<th scope="col">
AVG
</th>
<th scope="col">
MAX
</th>
<th scope="col">
SUM
</th>
<th scope="col">
INT
</th>
</tr>
</thead>
<tbody>
<tr class="webgrid3-row-style">
<td class="col1Width" style="display: none;"> <span id="SensorID">1</span> </td>
<td class="col1Width" style="display: none;"> <span id="DeviceID">1</span> </td>
<td class="col1Width" style="display: none;"> <span id="SensorType" class="SensorType">10</span> </td>
<td class="col2Width"> <span><label id="SensorName">Soil Temperature </label> </span> </td>
<td class="col1Width"><span class="Val"> <input id="val" name="val" type="checkbox" value="true"><input name="val" type="hidden" value="false"> </span></td>
<td class="col1Width"><span class="Min"> <input id="min" name="min" type="checkbox" value="true"><input name="min" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Avg"> <input id="avg" name="avg" type="checkbox" value="true"><input name="avg" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Max"> <input id="max" name="max" type="checkbox" value="true"><input name="max" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Sum" style="display: none;"> <input id="sum" name="sum" type="checkbox" value="true"><input name="sum" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Int" style="display: none;"> <input id="int" name="int" type="checkbox" value="true"><input name="int" type="hidden" value="false"> </span> </td>
</tr>
<tr class="webgrid3-alternating-row">
<td class="col1Width" style="display: none;"> <span id="SensorID">2</span> </td>
<td class="col1Width" style="display: none;"> <span id="DeviceID">1</span> </td>
<td class="col1Width" style="display: none;"> <span id="SensorType" class="SensorType">1</span> </td>
<td class="col2Width"> <span><label id="SensorName">Soil Moisture na 15cm</label> </span> </td>
<td class="col1Width"><span class="Val"> <input id="val" name="val" type="checkbox" value="true"><input name="val" type="hidden" value="false"> </span></td>
<td class="col1Width"><span class="Min"> <input id="min" name="min" type="checkbox" value="true"><input name="min" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Avg"> <input id="avg" name="avg" type="checkbox" value="true"><input name="avg" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Max"> <input id="max" name="max" type="checkbox" value="true"><input name="max" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Sum" style="display: none;"> <input id="sum" name="sum" type="checkbox" value="true"><input name="sum" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Int" style="display: none;"> <input id="int" name="int" type="checkbox" value="true"><input name="int" type="hidden" value="false"> </span> </td>
</tr>
<tr class="webgrid3-row-style">
<td class="col1Width" style="display: none;"> <span id="SensorID">3</span> </td>
<td class="col1Width" style="display: none;"> <span id="DeviceID">1</span> </td>
<td class="col1Width" style="display: none;"> <span id="SensorType" class="SensorType">1</span> </td>
<td class="col2Width"> <span><label id="SensorName">Soil Moisture na 30cm</label> </span> </td>
<td class="col1Width"><span class="Val"> <input id="val" name="val" type="checkbox" value="true"><input name="val" type="hidden" value="false"> </span></td>
<td class="col1Width"><span class="Min"> <input id="min" name="min" type="checkbox" value="true"><input name="min" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Avg"> <input id="avg" name="avg" type="checkbox" value="true"><input name="avg" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Max"> <input id="max" name="max" type="checkbox" value="true"><input name="max" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Sum" style="display: none;"> <input id="sum" name="sum" type="checkbox" value="true"><input name="sum" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Int" style="display: none;"> <input id="int" name="int" type="checkbox" value="true"><input name="int" type="hidden" value="false"> </span> </td>
</tr>
<tr class="webgrid3-alternating-row">
<td class="col1Width" style="display: none;"> <span id="SensorID">4</span> </td>
<td class="col1Width" style="display: none;"> <span id="DeviceID">1</span> </td>
<td class="col1Width" style="display: none;"> <span id="SensorType" class="SensorType">101</span> </td>
<td class="col2Width"> <span><label id="SensorName">Leaf wetness prvi</label> </span> </td>
<td class="col1Width"><span class="Val"> <input id="val" name="val" type="checkbox" value="true"><input name="val" type="hidden" value="false"> </span></td>
<td class="col1Width"><span class="Min" style="display: none;"> <input id="min" name="min" type="checkbox" value="true"><input name="min" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Avg" style="display: none;"> <input id="avg" name="avg" type="checkbox" value="true"><input name="avg" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Max" style="display: none;"> <input id="max" name="max" type="checkbox" value="true"><input name="max" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Sum"> <input id="sum" name="sum" type="checkbox" value="true"><input name="sum" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Int" style="display: none;"> <input id="int" name="int" type="checkbox" value="true"><input name="int" type="hidden" value="false"> </span> </td>
</tr>
<tr class="webgrid3-row-style">
<td class="col1Width" style="display: none;"> <span id="SensorID">5</span> </td>
<td class="col1Width" style="display: none;"> <span id="DeviceID">1</span> </td>
<td class="col1Width" style="display: none;"> <span id="SensorType" class="SensorType">201</span> </td>
<td class="col2Width"> <span><label id="SensorName">Ait temperature </label> </span> </td>
<td class="col1Width"><span class="Val"> <input id="val" name="val" type="checkbox" value="true"><input name="val" type="hidden" value="false"> </span></td>
<td class="col1Width"><span class="Min" style="display: none;"> <input id="min" name="min" type="checkbox" value="true"><input name="min" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Avg" style="display: none;"> <input id="avg" name="avg" type="checkbox" value="true"><input name="avg" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Max" style="display: none;"> <input id="max" name="max" type="checkbox" value="true"><input name="max" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Sum" style="display: none;"> <input id="sum" name="sum" type="checkbox" value="true"><input name="sum" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Int"> <input id="int" name="int" type="checkbox" value="true"><input name="int" type="hidden" value="false"> </span> </td>
</tr>
<tr class="webgrid3-alternating-row">
<td class="col1Width" style="display: none;"> <span id="SensorID">6</span> </td>
<td class="col1Width" style="display: none;"> <span id="DeviceID">1</span> </td>
<td class="col1Width" style="display: none;"> <span id="SensorType" class="SensorType">202</span> </td>
<td class="col2Width"> <span><label id="SensorName">Air humidity </label> </span> </td>
<td class="col1Width"><span class="Val"> <input id="val" name="val" type="checkbox" value="true"><input name="val" type="hidden" value="false"> </span></td>
<td class="col1Width"><span class="Min" style="display: none;"> <input id="min" name="min" type="checkbox" value="true"><input name="min" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Avg" style="display: none;"> <input id="avg" name="avg" type="checkbox" value="true"><input name="avg" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Max" style="display: none;"> <input id="max" name="max" type="checkbox" value="true"><input name="max" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Sum" style="display: none;"> <input id="sum" name="sum" type="checkbox" value="true"><input name="sum" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Int"> <input id="int" name="int" type="checkbox" value="true"><input name="int" type="hidden" value="false"> </span> </td>
</tr>
<tr class="webgrid3-row-style">
<td class="col1Width" style="display: none;"> <span id="SensorID">7</span> </td>
<td class="col1Width" style="display: none;"> <span id="DeviceID">1</span> </td>
<td class="col1Width" style="display: none;"> <span id="SensorType" class="SensorType">203</span> </td>
<td class="col2Width"> <span><label id="SensorName">Wind speed </label> </span> </td>
<td class="col1Width"><span class="Val"> <input id="val" name="val" type="checkbox" value="true"><input name="val" type="hidden" value="false"> </span></td>
<td class="col1Width"><span class="Min" style="display: none;"> <input id="min" name="min" type="checkbox" value="true"><input name="min" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Avg" style="display: none;"> <input id="avg" name="avg" type="checkbox" value="true"><input name="avg" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Max" style="display: none;"> <input id="max" name="max" type="checkbox" value="true"><input name="max" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Sum" style="display: none;"> <input id="sum" name="sum" type="checkbox" value="true"><input name="sum" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Int"> <input id="int" name="int" type="checkbox" value="true"><input name="int" type="hidden" value="false"> </span> </td>
</tr>
<tr class="webgrid3-alternating-row">
<td class="col1Width" style="display: none;"> <span id="SensorID">8</span> </td>
<td class="col1Width" style="display: none;"> <span id="DeviceID">1</span> </td>
<td class="col1Width" style="display: none;"> <span id="SensorType" class="SensorType">204</span> </td>
<td class="col2Width"> <span><label id="SensorName">Wind direction </label> </span> </td>
<td class="col1Width"><span class="Val"> <input id="val" name="val" type="checkbox" value="true"><input name="val" type="hidden" value="false"> </span></td>
<td class="col1Width"><span class="Min" style="display: none;"> <input id="min" name="min" type="checkbox" value="true"><input name="min" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Avg" style="display: none;"> <input id="avg" name="avg" type="checkbox" value="true"><input name="avg" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Max" style="display: none;"> <input id="max" name="max" type="checkbox" value="true"><input name="max" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Sum" style="display: none;"> <input id="sum" name="sum" type="checkbox" value="true"><input name="sum" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Int"> <input id="int" name="int" type="checkbox" value="true"><input name="int" type="hidden" value="false"> </span> </td>
</tr>
<tr class="webgrid3-row-style">
<td class="col1Width" style="display: none;"> <span id="SensorID">9</span> </td>
<td class="col1Width" style="display: none;"> <span id="DeviceID">1</span> </td>
<td class="col1Width" style="display: none;"> <span id="SensorType" class="SensorType">205</span> </td>
<td class="col2Width"> <span><label id="SensorName">Precipitation </label> </span> </td>
<td class="col1Width"><span class="Val"> <input id="val" name="val" type="checkbox" value="true"><input name="val" type="hidden" value="false"> </span></td>
<td class="col1Width"><span class="Min" style="display: none;"> <input id="min" name="min" type="checkbox" value="true"><input name="min" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Avg" style="display: none;"> <input id="avg" name="avg" type="checkbox" value="true"><input name="avg" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Max" style="display: none;"> <input id="max" name="max" type="checkbox" value="true"><input name="max" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Sum" style="display: none;"> <input id="sum" name="sum" type="checkbox" value="true"><input name="sum" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Int"> <input id="int" name="int" type="checkbox" value="true"><input name="int" type="hidden" value="false"> </span> </td>
</tr>
<tr class="webgrid3-alternating-row">
<td class="col1Width" style="display: none;"> <span id="SensorID">10</span> </td>
<td class="col1Width" style="display: none;"> <span id="DeviceID">1</span> </td>
<td class="col1Width" style="display: none;"> <span id="SensorType" class="SensorType">206</span> </td>
<td class="col2Width"> <span><label id="SensorName">Solar radiation </label> </span> </td>
<td class="col1Width"><span class="Val"> <input id="val" name="val" type="checkbox" value="true"><input name="val" type="hidden" value="false"> </span></td>
<td class="col1Width"><span class="Min" style="display: none;"> <input id="min" name="min" type="checkbox" value="true"><input name="min" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Avg" style="display: none;"> <input id="avg" name="avg" type="checkbox" value="true"><input name="avg" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Max" style="display: none;"> <input id="max" name="max" type="checkbox" value="true"><input name="max" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Sum" style="display: none;"> <input id="sum" name="sum" type="checkbox" value="true"><input name="sum" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Int"> <input id="int" name="int" type="checkbox" value="true"><input name="int" type="hidden" value="false"> </span> </td>
</tr>
<tr class="webgrid3-row-style">
<td class="col1Width" style="display: none;"> <span id="SensorID">51</span> </td>
<td class="col1Width" style="display: none;"> <span id="DeviceID">1</span> </td>
<td class="col1Width" style="display: none;"> <span id="SensorType" class="SensorType">20</span> </td>
<td class="col2Width"> <span><label id="SensorName">Battery </label> </span> </td>
<td class="col1Width"><span class="Val"> <input id="val" name="val" type="checkbox" value="true"><input name="val" type="hidden" value="false"> </span></td>
<td class="col1Width"><span class="Min"> <input id="min" name="min" type="checkbox" value="true"><input name="min" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Avg"> <input id="avg" name="avg" type="checkbox" value="true"><input name="avg" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Max"> <input id="max" name="max" type="checkbox" value="true"><input name="max" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Sum" style="display: none;"> <input id="sum" name="sum" type="checkbox" value="true"><input name="sum" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Int" style="display: none;"> <input id="int" name="int" type="checkbox" value="true"><input name="int" type="hidden" value="false"> </span> </td>
</tr>
<tr class="webgrid3-alternating-row">
<td class="col1Width" style="display: none;"> <span id="SensorID">56</span> </td>
<td class="col1Width" style="display: none;"> <span id="DeviceID">1</span> </td>
<td class="col1Width" style="display: none;"> <span id="SensorType" class="SensorType">101</span> </td>
<td class="col2Width"> <span><label id="SensorName">Leaf wetness drugi</label> </span> </td>
<td class="col1Width"><span class="Val"> <input id="val" name="val" type="checkbox" value="true"><input name="val" type="hidden" value="false"> </span></td>
<td class="col1Width"><span class="Min" style="display: none;"> <input id="min" name="min" type="checkbox" value="true"><input name="min" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Avg" style="display: none;"> <input id="avg" name="avg" type="checkbox" value="true"><input name="avg" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Max" style="display: none;"> <input id="max" name="max" type="checkbox" value="true"><input name="max" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Sum"> <input id="sum" name="sum" type="checkbox" value="true"><input name="sum" type="hidden" value="false"> </span> </td>
<td class="col1Width"> <span class="Int" style="display: none;"> <input id="int" name="int" type="checkbox" value="true"><input name="int" type="hidden" value="false"> </span> </td>
</tr>
</tbody>

所以我现在想要获取每行的每个复选框(总共有六个复选框)的每个值(即使它是假的)(可以是从零到任何数字,具体取决于有多少个 SensorID) (这是唯一的)DeviceID(每行都相同))。但我不知道如何迭代每一行。我尝试使用 FormCollection,但这对我来说不起作用,有人有任何其他建议可以帮助我吗?

public ActionResult InsertSensorsInExistingPredefineView(FormCollection sensorCollection)
{

foreach (var row in sensorCollection.AllKeys)

bool _val = sensorCollection["val"] != "false";
bool _min = sensorCollection["min"] != "false";
bool _avg = sensorCollection["avg"] != "false";
bool _max = sensorCollection["max"] != "false";
bool _sum = sensorCollection["sum"] != "false";
bool _int = sensorCollection["int"] != "false";

if (//some logic checking for at least one true value)
{
//save to some db table acording to sensorID....
}

}
return view;
}

我做了整个 != "false"事情,因为复选框以字符串形式返回值,就像如果选中则以“true,false”形式出现的字符串,如果未选中则以“false”形式返回的字符串。 我在这里一定做错了什么,我刚刚编辑了我的第一行(SensorID),认为它可以作为计数器,但我仍然在挣扎。

我不知道在这里要做什么,我是否有机会使用 Javascript/jQuery 完成我的任务,然后将结果发送到 Controller ?

我只是尝试看看它是否会迭代每一行并获取值:

    <input type="submit" class="DoSomething" value="Do it" />
foreach (WebGridRow row in gridSensorChoose.Rows)
{
<script type="text/javascript">
$(function () {
$(".DoSomething").on("click", function () {
var tr = $(this).parents('tr:first');
var sensorID = tr.find(".SensorID").html();
var _val = tr.find(".Val").html();
var _min = tr.find(".Min").html();
var _avg = tr.find(".Avg").html();
var _max = tr.find(".Max").html();
var _sum = tr.find(".Sum").html();
var _int = tr.find(".Int").html();
})
if (_val == true || _min =! true || _avg == true || _max == true || _sum == true || _int == true ||){
//ajax send all vars to controller
}
//and now iterate through next row

})
</script>

也许我可以在java脚本中写出类似的东西,并在每次结束迭代时将其发送到 Controller ?然后它开始一个新的行,直到没有更多的行。

最佳答案

根据您的代码行,我发现您误解了某些内容

foreach (var row in sensorCollection.AllKeys) 
{

}

sensorCollection 中的值不是行。它们是从 View 传递的字段。

您的 HTML 有很多同名的输入。举个例子:

<input id="val" name="val" type="checkbox" value="true">

sensorCollection.AllKeys 将包含“val”的多个条目 - 网格上的每一行都有一个条目。您将迭代每个值,然后忽略该值并再次检索该值。本质上是这样的

foreach (var row in sensorCollection.AllKeys)
{
bool _val = sensorCollection["val"] != "false";
bool _min = sensorCollection["min"] != "false";
bool _avg = sensorCollection["avg"] != "false";
bool _max = sensorCollection["max"] != "false";
bool _sum = sensorCollection["sum"] != "false";
bool _int = sensorCollection["int"] != "false";
}

相当于:

for(int i = 0; i < number_of_rows; i++)
{
bool _val = sensorCollection["val"] != "false";
bool _min = sensorCollection["min"] != "false";
bool _avg = sensorCollection["avg"] != "false";
bool _max = sensorCollection["max"] != "false";
bool _sum = sensorCollection["sum"] != "false";
bool _int = sensorCollection["int"] != "false";
}

看看i 在那里是如何不相关的? row 也是如此。您没有引用它,因此这些值将始终相同 - 可能是网格上第一行的值。

你需要做这样的事情

// find the number of values for "val" in the collection
// build a for loop that iterates over the collection
for(int i = 0; i < sensorCollection.AllKeys.Where(k => k == "val").Count(); i++)
{
// get the nth of each key, where n is the instance of "val"
bool _val = sensorCollection.AllKeys.Where(k => k == "val")[i] != "false";
// handle the other values (I'm too lazy to type them out)
// save out the data
}

更新

好的,我构建了一个新的 MVC 应用程序并复制了您的网格和回发,这就是我发现的内容。

首先,sensorCollection.AllKeys中有6个值 - 每列一个值(val,min,avg,max,sum,int)

其次,由于某种原因,数据被编码为串联字符串。因此,如果您勾选第一个 val 复选框,则 sensorCollection[0] = "true,false,false,false,false,false,false,false,false,false,false,false,false"

我没想到会这样,这有点奇怪,但我们会解决它。这段代码应该可以解决你的问题:

public ActionResult InsertSensorsInExistingPredefineView(FormCollection sensorCollection)
{
bool[] vals = sensorCollection["val"].Split(',').Select(x => Convert.ToBoolean(x)).ToArray();
bool[] mins = sensorCollection["min"].Split(',').Select(x => Convert.ToBoolean(x)).ToArray();
bool[] avgs = sensorCollection["avg"].Split(',').Select(x => Convert.ToBoolean(x)).ToArray();
bool[] maxs = sensorCollection["max"].Split(',').Select(x => Convert.ToBoolean(x)).ToArray();
bool[] sums = sensorCollection["sum"].Split(',').Select(x => Convert.ToBoolean(x)).ToArray();
bool[] ints = sensorCollection["int"].Split(',').Select(x => Convert.ToBoolean(x)).ToArray();

for (int i = 0; i < vals.Count(); i++)
{
// your first row, "Soil Temperature":
bool val = vals[i];
bool min = mins[i];
// etc
}

}

关于javascript - 如何从 MVC 项目中的每个表行获取每个值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27295444/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com