2011-02-14 4 views
0

안녕하세요 여러분, 내보기에 드롭 다운 목록과 제출 단추가 있습니다. 사용자가 드롭 다운 목록에서 데이터베이스에서 데이터를 가져 오는 컨트롤러에서 작업 메서드를 호출하는 항목을 선택할 수있게하려고합니다.mvc3 html.Dropdownlist() 및 html.beginform()

또한 단추가 있으며 사용자가 표의 확인란을 선택하고 제출 단추를 클릭하여 확인란의 값을 컨트롤러의 작업 메서드에 전달할 수있게하려고합니다.

문제는 제출 버튼 "DiscontinueProduct"및 의 드롭 다운 목록 ("GetProductByID")에 대한 작업 메서드가 아닌 드롭 다운 목록에서 항목을 선택하면 누군가 내가 ' 잘못하고있는거야? 여기 내 코드가 있습니다.

미리 감사드립니다.

=============

보기

<div> 
@Using Html.BeginForm("GetProductByID", "Product") 

    @Html.DropDownList("CategoryID", DirectCast(ViewData("Categories"), SelectList), " -- Choose One -- ", New With {Key .onchange = "$('form').submit();"}) 
End Using 
</div> 

@Using Html.BeginForm("DiscontinueProduct", "Product") 
    @<text> 
<table> 
    <tr> 
     <th></th> 
     <th>ProductName</th> 
     <th>SupplierID</th> 
     <th>CategoryID</th> 
     <th>Discontinued</th> 
    </tr> 
@For Each item In Model 
    @<tr> 
     <td> 
      @Html.ActionLink("Edit", "Edit", New With {.id = item.ProductID}) | 
      @Html.ActionLink("Details", "Details", New With {.id = item.ProductID}) | 
      @Html.ActionLink("Delete", "Delete", New With {.id = item.ProductID}) 
     </td> 
     <td>@item.ProductName</td> 
     <td>@item.SupplierID</td> 
     <td>@item.CategoryID 
      <input type="checkbox" name="task" id="isTaskSelected" value=" @item.CategoryID.ToString() " /> 
     </td> 
     <td>@item.Discontinued</td> 
    </tr> 
Next 

</table> 
<div id="btncomplete" style="display: none"> 
    <input type="submit" value="Discontinue" />   
</div> 
</text> 
End Using 

=====================

컨트롤러

Function GetProductByID(ByVal id As Integer) As ActionResult 

Dim cquery2 = From product In db.Products 
         Where product.CategoryID = id 
      viewmodel.ProductList = cquery2.ToList() 
      Return PartialView("Products", viewmodel.ProductList) 
Return PartialView("Products", viewmodel.ProductList) 

End Function 


    <HttpPost()> _ 
    Function DiscontinueProduct(ByVal collection As FormCollection) As ActionResult 
     Try 
      ' Code to update product field as discontinue. 


      Return RedirectToAction("Index") 
     Catch 
      Return View() 
     End Try 
    End Function 

답변