[英]CheckBox with Comma Separated string values
我是asp.net mvc的新手,我正在嘗試處理保存和檢索checkBox檢查值。
在我看來,我有以下復選框
<input type="checkbox" id="cabling in coduit" name="Prepration" value="cabling in coduit"/>cabling in coduit<br />
<input type="checkbox" id="Power to be done by liteStart" name="Prepration" value="Power to be done by liteStart"/>Power to be done by liteStart<br />
<input type="checkbox" id="Other - pls spec" name="Prepration" value="Other - pls spec"/>Other - pls spec<br />
在我的控制器中:
String vals=Request.Form["Prepration"];
我將檢查值作為逗號分隔的字符串獲取,並將該字符串保存到數據庫列中。
現在,當我檢索值時,我會看到類似下面的內容。
電源線布線,電源由liteStart完成
如何使用逗號分隔的字符串在我的編輯視圖中選中相關復選框
那么你可以做這樣的事情
if(vals.indexOf("cabling in coduit") > -1 ){
$('#cabling in coduit').prop('checked', true);
}
else if(vals.indexOf("Power to be done by liteStart") > -1 ){
$('#Power to be done by liteStart').prop('checked', true);
}
else if(vals.indexOf("Other - pls spec") > -1 ){
$('#Other - pls spec').prop('checked', true);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.