2017-07-14 68 views
-1

我創建了部分視圖,並在同一頁面中將它用於n次。局部視圖放置在手風琴內(div),並且當單擊複選框時,應該禁用文本框。mvc +局部視圖+複選框單擊事件

當我渲染使用局部視圖5次的頁面,並單擊複選框時,文本框僅在第一個局部視圖中被禁用。相同的功能在任何其他功能中都不起作用。

當我將調試器放入所有部分視圖時,它會觸發,但是文本框不會被禁用。這隻適用於第一部分視圖,但在其餘部分失敗。

請找到下面的代碼..

<table> 
    <tr> 
     <th>Select Recurrance:</th> 
     <th>Start DateTime:</th> 
     <th>End DateTime:</th> 
    </tr> 
    <tr> 
     <td> 
      <div style="margin-top: -0.0em;"> 
       <select id="Recurrances" onchange="SubmitRecurrance(this)"> 
        <option selected="selected" value="1">Run Continuosly</option> 
        <option value="2">Run on Schedule</option> 
       </select> 
       <br /> 
       @Html.ValidationMessageFor(model => model.Recurrance) 
      </div> 
     </td> 
     <td> 
      <div style="margin-top: -0.0em;"> 
       @Html.TextBoxFor(model => model.StartDateTime, new { @class = "form-control date-picker", @placeholder = "Start Date&Time", id = "starttime", onkeyup = "FormDirty();" }) 
       <br /> 
       @Html.ValidationMessageFor(model => model.StartDateTime) 
      </div> 
     </td> 
     <td> 
      <div style="margin-top: -0.0em;"> 
       @Html.TextBoxFor(model => model.EndDateTime, new { @class = "form-control date-picker", @placeholder = "End Date&Time", id = "endtime", onkeyup = "FormDirty();" }) 
       <br /> 
       @Html.ValidationMessageFor(model => model.StartDateTime) 
      </div> 
     </td> 
    </tr> 
    <tr> 
     <td id="divnoenddate"> 
      <div> 
       <span> No End Date</span>@Html.CheckBox("NoEndDate", false, new { id = "noenddate", onchange = "javascript:ChangeCheckBox()" }) 
       <br /> 
      </div> 
     </td> 
     <td id="recureveryoption"> 
      <span style="font-weight:bold;">Recur Every:</span> <div> 
       <select id="RecurEvery"> 
        <option selected="selected" value="1">Daily</option> 
        <option value="2">Weekly</option> 
        <option value="3">Monthly</option> 
        <option value="4">Yearly</option> 
       </select> 
      </div> 
     </td> 
     <td> 
      <div> 
       <input type="submit" value="Save" style=" width: 8em;height: 2em;text-align: center;padding-top: 6px;background: #0082BF;font-size: 1em; color: #0082BF; cursor:pointer; color:white;font-size: 1em; padding-left:6px; padding-right:6px;padding-bottom:6px;" onclick="SubmitChanges()" /> 
      </div> 
     </td> 

    </tr> 

</table> 

function ChangeCheckBox() 
    { 
     if (document.getElementById("Recurrances").value != 1) 
     { 
      debugger; 
      if (document.getElementById('noenddate').checked == true) 
      { 
       document.getElementById("endtime").disabled = true; 
      } 
      else 
      { 
       document.getElementById("endtime").disabled = false; 
      } 
     } 
    } 

我指上述局部視圖:

<div> 
    @Html.Partial("~/Views/Settings/ScedularControl.cshtml") 
</div> 
+0

你能提供更多的細節,代碼或小提琴等... –

+0

你能告訴我們H TML與複選框(es)和Javascript一起使用? – JNYRanger

回答

0

發送到比使用複選框像局部視圖的參數指標,下面的HTML幫助列表項:

@Html.CheckBox("SameModel["+index+"].Checked",false)