2013-05-17 3 views
1

저는 프로젝트 중 하나에 대해 ASP.NET MVC 면도기를 테스트 중이므로 문제가 발생합니다. 현재 해결 방법이 없습니다. 어쩌면 누군가 나를 도울 수 있습니다. 두 개의 입력 요소가있는 페이지가 있습니다. 모델 테이블로 채워지는 textBox와 DropdownList. 이제 그 필드를 복제 할 수있는 가능성을 원합니다. 사용자가 더 많은 입력을 한 다음 한 줄만 만들 수 있습니다. 다른 방법을 찾았지만 항상 DropDownList가 느슨한 이유가 있습니다. 나는 너무 js에 맞지 않는다. 그래서 어쩌면 나는 dropdownlist를 묶는 좋은 방법을 놓쳤다.ASP.NET MVC 면도기 동적으로 새 텍스트 상자 및 드롭 다운 목록을 양식에로드하십시오.

@model Tumormodelle.Models.SearchModel 
<table> 
    @for (int i = 0; i < (int) Model.SearchCount ;i++) 
{ <tr> 
    <th>@if(i > 0){<select name="ConnectorList" id="ConnectorList"> 
     <option value="AND" @(Model.ConnectorList.ElementAt(i-1).Equals("AND") ?"selected":"")>AND</option> 
     <option value="OR" @(Model.ConnectorList.ElementAt(i-1).Equals("OR") ?"selected":"") >OR</option> 
     <option value="NAND" @(Model.ConnectorList.ElementAt(i-1).Equals("NAND") ?"selected":"") >NAND</option> 
     <option value="NOR" @(Model.ConnectorList.ElementAt(i-1).Equals("NOR") ?"selected":"") >NOR</option> 
        </select>}</th> 
<th> <input name="SearchInput" id="SearchInput" type="text" value="@(Model.SearchList.ElementAt(i) as String)" /></th> 
<th><select name="SelectionList" id="SelectionList"> 
@for (int j = 0; j < Model.SelectedList.Count(); j++) 
{<option value="@j" @(Model.Selection.ElementAt(i).Equals(j) ?"selected":"")> @(Model.SelectedList.ElementAt(j).Name as String)</option> 
} </select> 
</th></tr>} 

</table><p> <button name="button" value="add" class="formbutton" >Add one more search field</button> <button name="button" value="sub" class="formbutton" >Remove one search field</button></p> 

답변

2

스티븐 샌더슨이를 달성하는 방법을 단계에 의해 excellent article 설명하는 단계를 썼다으로 해결한다 : 도움을

@{ 
    ViewBag.Title = "SelectionList"; 
} 
<h1>Search for Models</h1> 
<h2>Search Request</h2> 
<fieldset> 
<legend>Here you can Search for all accessible TumorModels</legend> 
@using(Html.BeginForm("SearchTumorModel","Search",FormMethod.Post, new { @class = "searchForm"})) 
{ 
    <table id="formTable"> 
     <thead> 
      <tr> 
       <th>Specification</th> 
       <th>Input</th> 
      </tr> 
     </thead> 
     <tbody> 
      <tr> 
       <td> @Html.TextBox("Search") in</td> 
       <td> @Html.DropDownList("SelectionList", (IEnumerable<SelectListItem>) ViewBag.SelectionList) </td> 
      </tr> 
     </tbody> 
    </table> 
    <p> <button name="button" value="add" class="formbutton" >Add one more search field</button></p> 
    <p> 
     <button name="button" value="search" class="formbutton" >Search</button> 
     <button name="button" value="clear" class="formbutton" >Clear</button> 
    </p> 
} 
</fieldset> 

감사합니다 :)

업데이트 : 여기 내 페이지입니다. 새로운 레코드를 포함하는 부분 뷰를 반환하는 컨트롤러 동작과 사용자가 새 행을 추가하기로 결정할 때 AJAX 호출을 사용하여 호출되는 컨트롤러 동작이 있습니다. 또한 Html.BeginCollectionItem이라는 사용자 정의 도우미를 사용하여 행을 추가/삭제할 때 standard naming convention이 존중되도록 입력 필드의 이름에 비 순차 색인 (Guids)을 생성합니다.

관련 문제