gpt4 book ai didi

javascript - 如何获取@htmlDropDownList 选中的值?

转载 作者:行者123 更新时间:2023-11-30 09:05:59 25 4
gpt4 key购买 nike

我有一个 @htmlDropDownList 作为

@Html.DropDownList("MyList", new SelectList(Model.List, "Id", "Movie"))

在 mvc3 View 中。

如何使用 javascript 捕获此下拉列表的选定值,并使用它根据选定项更改 View 的内容?

最佳答案

获取值很简单:

$('#MyList').val()

对于问题的第二部分,我需要更多信息。

更新

我们将如何使用该值?

//get the url for the movie description , define id  as 0, so it is easier to replace lateron.
var moviedescriptionUrl = '@Url.Action("details", "movies", new { id = 0})';

//get the movieid
var movieID = $('#MyList').val();

//update a div
$('#movie-description').load(moviedescriptionUrl.replace('0', movieID));

假设我有一个返回部分 View 的“详细信息”操作。

关于javascript - 如何获取@htmlDropDownList 选中的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4944657/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com