javascript - Ajax Modal Not Updating Target ID -


i have following modal add comments blog when submit form instead of updating target id list of added comments redirect new page list of comments? how update target id display new comment along others?

 <button type="button" class="btn btn-primary" data-toggle="modal"    data-target="#mymodal"> launch demo modal</button>  <div class="modal fade" id="mymodal" tabindex="-1" role="dialog" aria-labelledby="mymodallabel">   <div class="modal-dialog" role="document">     <div class="modal-content">     @using (ajax.beginform("addcomment", "blog", new ajaxoptions                 {                     httpmethod = "post",                     insertionmode = insertionmode.replace,                     updatetargetid = "comments",                     loadingelementid = "progress",                     onsuccess = "$('#mymodal').modal('hide');"                  }))       {         <div class="modal-header">             <button type="button" class="close" data-dismiss="modal" aria-label="close">                 <span aria-hidden="true">&times;</span>             </button>             <h4 class="modal-title" id="mymodallabel">add comment</h4>         </div>         <div class="modal-body">              @html.validationsummary(true)              @html.hiddenfor(model => model.blog.blogid)               <div class="form-group">                  @html.labelfor(model => model.blogcomment.comment)                  @html.textareafor(model => model.blogcomment.comment, 4, 104, new { @class = "form-control" })                  @html.validationmessagefor(model => model.blogcomment.comment)              </div>          </div>         <div class="modal-footer">            <button type="button" class="btn btn-primary">save changes</button>            <button type="button" class="btn btn-primary" data-dismiss="modal">close</button>         </div>       }   </div>  </div> </div>   <div id="comments">    @html.action("comments", "blog", new { id = model.blog.id }) </div>    public partialviewresult comments(int id) {     ienumerable<blogcomment> commentlist = _repository.getblogcomments(id);      return partialview("_blogcomments", commentlist);  }  public actionresult addcomment(// pramameters) {      if (modelstate.isvalid)      {           // save comment            if (request.isajaxrequest())            {              return redirecttoaction("comments", new { id = id });           }       }      else     {         //return modal errors          return partialview("_createcomment", blogviewmodel);      }   } 

the redirecttoaction triggering client-side redirect.

change return instead calls existing method returns partialviewresult:

 if (request.isajaxrequest())   {      return comments(id);  } 

update

also see comments below aspect i.e. unobtrusive ajax , jquery validate update.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -