【環境】
.NET VB (Microsoft Visual Studio 2010(sp1) .NET Framework 4.5.2)
MVC4
非同期通信を行う
View
@Using Ajax.BeginForm("TestFunc", "TestClass", New AjaxOptions With {.OnSuccess = "viewjs"})
@<div>
<input type="submit" value="送信" id="btnSendClick" />
<input type="text" id="code" />
<input type="text" id="name" />
</div>
End Using
<script type="text/javascript">
function viewjs(obj) {
//通信結果を画面項目に設定
$("#name").text(obj.name);
}
</script>
@<div>
<input type="submit" value="送信" id="btnSendClick" />
<input type="text" id="code" />
<input type="text" id="name" />
</div>
End Using
<script type="text/javascript">
function viewjs(obj) {
//通信結果を画面項目に設定
$("#name").text(obj.name);
}
</script>
.OnSuccess = "viewjs"
Contorollerとの通信結果後動作するJavaScript関数を定義
Contoroller
Public Class TestClassController
<HttpPost()> _
Public Function TestFunc(ByVal collection As FormCollection) As ActionResult
Dim model As New TestModel
If Not Request.IsAjaxRequest() Then
Return New EmptyResult()
End If
//画面入力したcodeでnameを取得するサービスクラス
model = _Service.TestForAjax(Me.Session, collection("code"))
Return Json(model)
End Function
End Class
<HttpPost()> _
Public Function TestFunc(ByVal collection As FormCollection) As ActionResult
Dim model As New TestModel
If Not Request.IsAjaxRequest() Then
Return New EmptyResult()
End If
//画面入力したcodeでnameを取得するサービスクラス
model = _Service.TestForAjax(Me.Session, collection("code"))
Return Json(model)
End Function
End Class
Model
Public Class TestModel
Public Property name As String
Public Sub New()
name = String.Empty
End Sub
End Class
Public Property name As String
Public Sub New()
name = String.Empty
End Sub
End Class
0 件のコメント:
コメントを投稿