asp.net mvc - Prevent reload on Ajax.BeginForm -


how can prevent page reloading when submitting form in partial view? there lot of examples seems non of them working me. have. partial view (razor) calls this:

@using (ajax.beginform("savereply", "home", null, new ajaxoptions { httpmethod = "post" }, new { target = "_self" })) {     <div class="input-group wall-comment-reply" style="width:100%">         @html.hidden("eventid", @item.eventid)         <input name="txtreply" type="text" class="form-control" placeholder="type message here...">         <span class="input-group-btn">             <button class="btn btn-primary" id="btn-chat" type="submit">                 <i class="fa fa-reply"></i> reply             </button>         </span>     </div> } 

then have action method in controller:

[httppost] public void savereply(string txtreply, string eventid) {     //some code  } 

the controller action fired after automatically redirected localhost/home/savereply

maybe problem partial view rendered string. took code from:

how render razor view string in asp.net mvc 3?

also amongs other things tried this:

http://geekswithblogs.net/blachniet/archive/2011/08/03/walkthrough-updating-partial-views-with-unobtrusive-ajax-in-mvc-3.aspx

i appreciate help.

i found problem.

it seems need reference unobtrusive scripts. install them nuget:

install-package microsoft.jquery.unobtrusive.ajax

and reference view calls partial view:

<script src="~/scripts/jquery.unobtrusive-ajax.min.js"></script> 

and miraculosly works without other changes. more explanations can found here:

[why ajax.beginform replace whole page?

and here:

[why unobtrusivejavascriptenabled = true disable ajax work?

it seems need use if using ajax.* helpers in mvc 3 , higher.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -