asp.net mvc 3 - Looking for MVC 3 tutorial with jQuery -
i looking tutorial shows how invoke mvc action , pass parameters. have dynamic "comment box" need save database. want use jquery send comment data rest method handle it.
i need refresh part of page data returned mvc action. data returned json.
i have seen tutoral scott guthrie, uses postback. need asynchronous communication through jquery.
very simple , small tutorial useful.
thanks
edit: using $.ajax()
calls of jquery
assuming have form on view allow user post comment:
@using (html.beginform("save", "comment", formmethod.post, new { id = "commentform" })) { @html.textareafor(x => x.comment) <input type="submit" value="comment" /> } <div id="result"></div>
you ajaxify using jquery:
$(function() { $('#commentform').submit(function() { $.ajax({ url: this.action, type: this.method, data: $(this).serialize(), success: function(result) { // refresh part of dom based ion result $('#result').html(result.someproperty); } }); return false; }); });
and controller action save comment , return json object used in success callback:
[httppost] public actionresult save(string comment) { // todo: save comment return json(new { someproperty = "some value" }); }
and here's tutorial progressive enhancement asp.net mvc 3 , jquery.
Comments
Post a Comment