MVC3下拉列表更改...加载数据

发布于 2024-12-17 18:52:56 字数 161 浏览 3 评论 0原文

我有一个 C#.Net MVC3 Web 应用程序。我的提案模型有一个编辑视图。编辑视图上有一个包含提案列表的下拉列表。要求是,当用户更改下拉列表中的选择时,所选提案需要由提案控制器加载。我能够提交编辑视图,但不知道如何获取 DropDownList 中的值来查找选择的提案。我确信这是非常可行的。有想法吗?

I have a C#.Net MVC3 web app. There is and Edit View for my Proposal Model. On the Edit View is a drop down list with a list of Proposals. The requirement is that, when a user changes the selectin in the Drop Down list, the selected proposal needs be loaded by the Proposal Controller. I am able to get the Edit View submitted, but don't know how to grab the value in the DropDownList to find what Proposal was selected. I'm sure this is very do-able. Ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枯寂 2024-12-24 18:52:56

您可以将下拉列表放入表单中,然后在选择更改时提交表单。这样,选定的值将自动发送到控制器操作。或者,如果您在选择更改时手动执行一些 AJAX 请求,您可以将所选值与请求一起发送:

$('#id_of_your_ddl').change(function() {
    var selectedProposal = $(this).val();
    $('#resultDiv').load('@Url.Action("Index", "Proposal")', { id: selectedProposal });
});

You could put the dropdownlist inside a form and then when the selection changes submit the form. This way the selected value will automatically be sent to the controller action. Or if you are manually doing some AJAX request when the selection changes you could send the selected value along with the request:

$('#id_of_your_ddl').change(function() {
    var selectedProposal = $(this).val();
    $('#resultDiv').load('@Url.Action("Index", "Proposal")', { id: selectedProposal });
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文