[英]Set default value of input field with read-only attribute
我有一種將持久性數據發布到SQL數據庫的表單。 在我的表單中,我首先將輸入字段設置為只讀,除非用戶選擇以下選項:
我的問題是,如果用戶選擇不在輸入字段中輸入值,則會收到此錯誤:
我嘗試在JavaScript中設置輸入的默認值,但收到相同的錯誤。
$("#lejeperiode").val(" ");
向數據庫中插入空字符串還是null都沒有關系。 這是我的輸入字段:
<input id="periodeInput" class="form-control" type="text" name="lejeperiode" value="@(Request.Form["lejeperiode"] != null ? Request.Form["lejeperiode"].ToString() : "")"/>
修改您的代碼以檢查string是否為空,如果是,則“”將是您的默認其他POST值。
cmd.Parameters.AddWithValue("@lejeperiode", string.IsNullOrEmpty(Request.Form["lejeperiode"]) ? "" : Request.Form["lejeperiode"].ToString())
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.