在JavaScript中隱藏字段值被存儲。存儲隱藏字段值並在mvc的下一頁顯示它們
但是,當點擊下一頁隱藏字段爲空時,它不具有來自上一頁的值。
爲什麼它不會在下一頁加載以前的值?
如何在隱藏字段中加載以前的值?
function AddRemoveCustomer(id) {
//$(".checkBoxClass").click(function (e) {
alert('in main function');
alert(id);
var CustomerIDArray = [];
var hidCID = document.getElementById("hfCustomerID");
if (hidCID != null && hidCID != 'undefined') {
var CustID = hidCID.value;
CustomerIDArray = CustID.split("|");
var currentCheckboxValue = id;
var index = CustomerIDArray.indexOf(currentCheckboxValue);
alert('index value:' + index);
debugger;
if (index == 0) {
alert('if');
CustomerIDArray.push(currentCheckboxValue);
alert('pushed value:' + CustomerIDArray);
} else {
alert('else');
var a = CustomerIDArray.splice(index, 1);
alert("a" + a);
}
hidCID.value = CustomerIDArray.join("|");
alert('Final' + hidCID.value);
} else {
alert('undefined');
}
//});
}
<table id="tblEmailScheduler" class="table-bordered col-offset-12">
<thead>
<tr class="label-primary">
<th style="padding:5px 15px;">
First Name
</th>
<th style="padding:5px 15px;">
Last Name
</th>
<th style="padding:5px 15px;">
Email ID
</th>
<th style="padding:5px 15px;">
Customer Type
</th>
<th style="padding:5px 15px;">
Customer Designation @Html.DropDownList("CustomerDesignation", new SelectList(ViewBag.SelectAllCustomerDesignationDDL, "Value", "Text"), new { id = "CustomerDesignationDDL" , name = "CustomerDesignationDDL" })
</th>
<th style="padding:5px 15px;">
Select All
<div class="checkbox control-group">
<label><input type="checkbox" id="cbSelectAll" /></label>
</div>
</th>
</tr>
</thead>
<tfoot>
<tr>
<th colspan="2">
EmailTemplate : @Html.DropDownList("EmailSubject", new SelectList(ViewBag.SelectAllEmailTemplateDDL, "Value", "Text"), new { id = "SelectAllEmailTemplateDDL" })
</th>
<th colspan="2">
Set Date And Time:
<input type="text" class="from-date-picker" readonly="readonly" />
</th>
<th colspan="2">
<input type="submit" value="Schedule" id="btnSubmit" class="btn btn-default" />
</th>
<td>
</td>
</tr>
</tfoot>
@foreach (var item in Model) {
<tr style="text-align:center">
<td id="tblFirstName">
@item.FirstName
</td>
<td id="tblLastName">
@item.LastName
</td>
<td id="tblEmailID">
@item.EmailID
</td>
<td id="tblCustomerType">
@item.CustomerType
</td>
<td id="tblCustomerDesignation">
@item.CustomerDesignation
</td>
<td>
<div class="checkbox control-group">
<label><input type="checkbox" id="@item.CustomerID" value="@item.CustomerID"
onclick="AddRemoveCustomer(@item.CustomerID)" class="checkBoxClass"/>
@*@Html.CheckBox("Select", new { id = "cbCustomer", item.CustomerID})*@</label>
</div>
</td>
</tr>
}
</table>
<input type="hidden" id="hfCustomerID" />
你能舉一些例子嗎? –
@ShridharSalunkhe如果您更新問題以顯示整個.cshtml視圖和您的控制器代碼,我將能夠更輕鬆地向您展示我的意思。 –
在這個表格中,當勾選框被勾選,然後勾選框的值被存儲在使用JavaScript的隱藏字段中。我使用mvcpaging nuget包進行分頁。當我檢查值時,它存儲在隱藏字段,當我去到下一頁隱藏字段是空的。我想獲取上一頁的檢查值並在隱藏字段中添加新的檢查值 –