代码之家  ›  专栏  ›  技术社区  ›  Leth

设置具有只读属性的输入字段的默认值

  •  0
  • Leth  · 技术社区  · 7 年前

    我有一个表单,将持久数据发布到SQL数据库。在我的表单中,我有一个输入字段,该字段最初设置为只读,除非用户选择一个选项:

    enter image description here

    我的问题是,如果用户选择不在输入字段中输入值,我会收到以下错误:

    enter image description here

    $("#lejeperiode").val(" ");
    

    在数据库中插入空字符串或null无关紧要。 这是我的输入字段:

    <input id="periodeInput" class="form-control" type="text" name="lejeperiode" value="@(Request.Form["lejeperiode"] != null ? Request.Form["lejeperiode"].ToString() : "")"/>
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   Adrian    7 年前

    cmd.Parameters.AddWithValue("@lejeperiode", string.IsNullOrEmpty(Request.Form["lejeperiode"]) ? "" : Request.Form["lejeperiode"].ToString())