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