下拉选项更改时更新表
我有一个表的一部分,其值取决于下拉列表中的值。当下拉列表的选定选项发生更改时,如何更新表格。
网格
@foreach (var choice in ViewData.Model.Options where choiceId == ViewData.Model.choiceLevelId)
{
<tr class='gridrow'>
<td>.....
下拉菜单
<div class="editor-field">
@Html.DropDownListFor(model => model.choiceLevelId,
(
...
I have a portion of a table whose values depend on the value in my dropdownlist. How can I update the the table when the selected option of the dropdownlist changes.
grid
@foreach (var choice in ViewData.Model.Options where choiceId == ViewData.Model.choiceLevelId)
{
<tr class='gridrow'>
<td>.....
dropdown
<div class="editor-field">
@Html.DropDownListFor(model => model.choiceLevelId,
(
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你说的是哪张桌子? ASP.NET MVC 不了解桌子或椅子。它适用于模型、控制器和视图。
因此,您有一个视图,其中呈现了一个
您必须在视图中使用 javascript 才能订阅此下拉列表的更改事件。然后您有几种可能性:
根据您的要求,您可以选择最适合您的技术。
让我用 jQuery 的示例来说明第一种方法:
以及将处理 AJAX 请求的控制器操作:
更新:
如果您想在选择更改时提交包含下拉列表的表单,您可以使用以下命令:
What table are you talking about? ASP.NET MVC has no knowledge of tables or chairs. It works with Models, Controllers and Views.
So you have a View in which you have rendered a
<select>
box and you want upon changing the value of this select box by the user to invoke a Controller Action passing the newly selected value to the server so that it can perform some processing. Am I right?You will have to use javascript in your View in order to subscribe to the change event of this dropdown. Then you have a couple of possibilities:
window.location.href
) to the controller action passing it the selected value as action argument.Depending on your requirements you could pick the technique that suites best for you.
Let me illustrate the first approach with an example using jQuery:
and your controller action that will handle the AJAX request:
UPDATE:
If you wanted to submit the form containing the dropdowns when the selection changes you could use the following: