asp.net mvc ajax

发布于 2024-09-05 18:46:40 字数 251 浏览 9 评论 0原文

我正在使用 dropdownlist html 帮助程序,并希望在值更改时对服务器执行 ajax 调用。我已经看到jquery代码dropdownlist.change...

我遇到的问题是我有一系列dropdownlist的名称dropdownlist_1,dropdownlist_2,...

我希望能够为每个dropdownlist指定相同的jquery函数。我无法找到在下拉列表 html 帮助器中指定函数名称的方法。

谢谢, 亨利

I'm using the dropdownlist html helper and would like to perform an ajax call to the server when the value changes. I have seen the jquery code dropdownlist.change...

The problem I have is that I have a series of dropdownlist's name dropdownlist_1, dropdownlist_2, ...

I would like to be able to specify the same jquery function for each of these dropdownlist's. I have not been able to find a way to specify the function name in the dropdownlist html helper.

Thanks,
Henry

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

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

发布评论

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

评论(2

糖果控 2024-09-12 18:46:40

不要尝试在 HtmlHelper 中指定它,而是将类名添加到每个下拉列表中:

<%=Html.DropDownList("ddlName", new {@class="ajaxDropDown"})%>

或者

<select class="ajaxDropDown" id="ddlOne">
  <option>1</option>
  <option>2</option>
  <option>3</option>
</select>
<select class="ajaxDropDown" id="ddlTwo">
  <option>Red</option>
  <option>Orange</option>
  <option>Blue</option>
</select>

然后使用类名通过 jQuery 连接事件:

$('.ajaxDropDown').change(function() {
  $.get('/test', function(data) {
    ...
  });
});

Instead of attempting to specify it in the HtmlHelper, add a class name to each of your dropdown lists:

<%=Html.DropDownList("ddlName", new {@class="ajaxDropDown"})%>

or

<select class="ajaxDropDown" id="ddlOne">
  <option>1</option>
  <option>2</option>
  <option>3</option>
</select>
<select class="ajaxDropDown" id="ddlTwo">
  <option>Red</option>
  <option>Orange</option>
  <option>Blue</option>
</select>

Then use the classname to hook up the event via jQuery:

$('.ajaxDropDown').change(function() {
  $.get('/test', function(data) {
    ...
  });
});
江湖彼岸 2024-09-12 18:46:40

试试这个:

<%=Html.DropDownList("TopItemsList", ViewData["ListData"], new { @onchange="javascript();" })%> 

你可以调用你想要的函数。

try this:

<%=Html.DropDownList("TopItemsList", ViewData["ListData"], new { @onchange="javascript();" })%> 

you can call the function you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文