How to pass a asp net object to javascript using vb net
On a razor view with an edit button to push asp.net model to the server, do the following.
Step 1 Create a javascript function to pass model to the server
function Update(e, tabname, model) { e.preventDefault(); data = {} data = model; obj = JSON.stringify({ modelOfData: data }) var request = $.ajax({ type: 'POST', data: obj, dataType: "json", cache: false, contentType: "application/json; charset=utf-8", url: GetServerURL() + "/" }); request.done(function () { ShowNotification("", request.ResponseStatus.Message, 1, 3500); });
Step 2 Then on the controller
Public Function Update(ByVal ImodelOfData As model) As JsonResult Dim ResponseStatus As New ResponseStatus ResponseStatus.Status = "Success" ResponseStatus.StatusCode = "200" ResponseStatus.Message = "Your agreement has been saved." ' your back end code return ResponseStatus End Function