![](/img/trans.png)
[英]How can I get a DropDownList selected value and send it to the controller in ASP.NET MVC 4 and using JavaScript?
[英]Can I bind asp.net dropdownlist using javascript/jquery?
我可以使用javascript / jquery绑定asp.net下拉列表吗? 我从Web方法的jquery ajax获取数据,因此我想避免此时的回发。 但是我仍然想做回发,并在使用客户端脚本绑定之后使用服务器端代码保存所有数据(即,我仍然能够执行此dropdownlist1.selecteditem.text
)。
是否可以,有人可以向我解释如何完成?
谢谢,
使用Json Ajax
句法:
$.ajax({
dataType: "json",
url: url,
data: data,
success: success
});
查看json的简单示例:
<script type="text/javascript">
$(document).ready(function () {
var msgbox = $("#status");
$("#Button1").click(function () {
$.ajax({
type: "POST",
//Page Name (in which the method should be called) and method name
url: "BeginJson.aspx/CheckDateTime",
// If you want to pass parameter or data to server side function you can try line
// data: "{}",
//else If you don't want to pass any value to server side function leave the data to blank line below
data: "{'args':'Somnath'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
//Got the response from server and render to the client
msgbox.html(msg.d);
}
});
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.