Tuesday

asp.net mvc ajax post from javascript

Following example demonstrate how to submit form in asp.net MVC for strict type view based on model:
(view has this instruction oin top:
@model MyModel
):

javascript part:
      
<script type="text/javascript">
$(document).ready(function() {
$("#GoButton").click(function() {
var frm = $(this).closest('form');
var params = frm.serialize();
$.ajax({
type: 'POST',
url: '@Url.ApplicationAction("MyPostAction", "myController")',
data: params,
cache: false,
success: function (data) {
alert('Completed');
},
error: function (xhr, data, message) {
//console.log(data + ": " + message);
},
dataType: "json"
});
return false;
});
});
</script>


on server side model variable will have updated with all values submitted in form and will have following parameters:
 
[HttpPost]
public ActionResult MyPostAction(MyModel model)
{

return Json("Ok");
}




No comments:

imagemagic add text to image

rem different types of text annotations on existing images rem cyan yellow orange gold rem -gravity SouthWest rem draw text and anno...