Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 使用Dropdownlist visual basic调用MVC actionResult_Jquery_Asp.net Mvc_Vb.net_Drop Down Menu_Onchange - Fatal编程技术网

Jquery 使用Dropdownlist visual basic调用MVC actionResult

Jquery 使用Dropdownlist visual basic调用MVC actionResult,jquery,asp.net-mvc,vb.net,drop-down-menu,onchange,Jquery,Asp.net Mvc,Vb.net,Drop Down Menu,Onchange,我希望dropdownlist在onChange事件之后触发对ActionResult的调用,而不是将整个表单提交给服务器。其思想是,必须将所选项目发送到服务器,以检查所选公司是否在数据库中可用,然后才能继续填写其他详细信息。类似地,当用户键入其名称时,onChange还应该触发一个事件来检查该用户在数据库中是否可用 index.vbhtml @Using Html.BeginForm("Authorise", "Login", FormMethod.Po

我希望dropdownlist在onChange事件之后触发对ActionResult的调用,而不是将整个表单提交给服务器。其思想是,必须将所选项目发送到服务器,以检查所选公司是否在数据库中可用,然后才能继续填写其他详细信息。类似地,当用户键入其名称时,onChange还应该触发一个事件来检查该用户在数据库中是否可用

index.vbhtml

@Using Html.BeginForm("Authorise", "Login", FormMethod.Post)
<div>
    @Html.DropDownListFor(Function(x) x.SelectedItems, Model.CompanyID, New With {Key .id = "CompanyID"})
</div>
<div>
   @Html.TextBoxFor(Function(model) model.UserName, New With {Key .id = "UserName"})
</div>
<div>
   @Html.TextBoxFor(Function(model) model.UserPassword, New With {Key .id = "UserPassword"})
</div>
End Using
LoginModel.cs

Public Class LoginModel
    Public Property CompanyID As String
    Public Property LoginErrorMessage As String
    Public Property Username() As String
    Public Property UserPassword() As String
    Public Property SelectedItems As IEnumerable(Of String)
    Public Property Items As IEnumerable(Of SelectListItem)
End Class

非常感谢您提供任何可能的解决方案或链接。

如果您没有安全问题,可以使用此 要实现您的要求,请执行以下步骤:

  • 在index.vbhtml中使用JQuery 从Dropdownlistfor客户端获取价值 然后使用AJAX通过POST发送数据

函数checkMyId(id){
$.ajax({
类型:“POST”,
url:“/Home/AjaxMethodeCheck”,
数据:'{id:'+id+'''}',
contentType:“应用程序/json;字符集=utf-8”,
数据类型:“json”,
成功:功能(响应){
警报(response.message);
var值=响应值;
//做这项工作。。。
},
故障:功能(响应){
警报(“故障”);
},
错误:函数(响应){
警报(“错误”);
},
});
}
$(文档).ready(函数(){
$(函数(){
$(“#YourDropDownId”).change(函数(){
var selected=$(this).find(“选项:selected”);
checkMyId(selected.val());
});
});
});
  • 在控制器中,您将接收数据并进行检查
  • 然后将json格式的结果发送回JQuery:

作为JsonResult的公共函数AjaxMethodeCheck(ByVal id作为字符串)
Dim Str As String=“Done!”,如果要发回消息。。。
如果要发回数据,请将Dim值设置为Integer=0。。。
'在vb.net中完成您的工作
Dim响应=新的,带有{
.id=id,
.message=Str,
.value=value}
返回Json(响应)
端函数
  • JQuery使用该结果(ajax成功:)

我认为应该在onchange函数中使用ajax。
Public Class LoginModel
    Public Property CompanyID As String
    Public Property LoginErrorMessage As String
    Public Property Username() As String
    Public Property UserPassword() As String
    Public Property SelectedItems As IEnumerable(Of String)
    Public Property Items As IEnumerable(Of SelectListItem)
End Class
    <HttpPost>
    Public Function AjaxMethodeCheck(ByVal id As String) As JsonResult

        Dim Str As String = "Done !"  ' if you want to send back message ...
        Dim value As Integer = 0      ' if you want to send back data ...

        ' Do your job in vb.net

        Dim response = New With {
        .id = id,
        .message = Str,
        .value = value}

        Return Json(response)
    End Function