如何将 jquery 值发送到控制器..?
我在视图中有一个用 jquery 处理的下拉列表。我需要知道如何将下拉列表中选定的项目发送到控制器,因为我需要此信息来执行特定操作,任何人都可以帮助我..?
这是我尝试过的 javascript 代码,但它不起作用:
$("#BtnPassType").click(function () {
var formData = $("#displaydropdown option:selected").val();
$.post("/EquipodeRed/Prueba/", { tipo: formData },
function (data) {
alert(data.toString());
}, "text");
});
这是按钮的 HTML 代码:
<input type="button" id="BtnPassType" value="Send Type" />
这是控制器代码
public String Prueba(string tipo)
{
string ubic = "Esta es la Ubicacion del equipo de tipo :";
return ubic + tipo;
}
我感谢一些帮助,提前致谢。 问候。
I have in the view a dropdownlist that I handle with jquery. I need to know how to send the selected Item of the dropdown to the controller, because I need this information to do a specific action, could anybody help me..??
Here's the javascript code I tried, but it doesn't work:
$("#BtnPassType").click(function () {
var formData = $("#displaydropdown option:selected").val();
$.post("/EquipodeRed/Prueba/", { tipo: formData },
function (data) {
alert(data.toString());
}, "text");
});
Here's the HTML code of the button:
<input type="button" id="BtnPassType" value="Send Type" />
And here's the Controller Code
public String Prueba(string tipo)
{
string ubic = "Esta es la Ubicacion del equipo de tipo :";
return ubic + tipo;
}
I appreciate some help, thanks in advance.
Regards.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的 AJAX 调用看起来没问题。您可以像这样简化它:
另外,最好让控制器操作返回操作结果:
当然,避免在 JavaScript 中硬编码 url,始终使用 url 助手:
You AJAX call seems fine. You could simplify it like this:
Also it is better to have controller actions return action results:
And of course avoid hardcoding urls in your javascripts, always use url helpers: