javascript - Post back with FormMethod.Post using a modal -


i have jquery datatable has custom buttons, when clicked boostrap modal called. modal asks wether user wants deactivate account.

in example2 datatable pass unique identifier (pid) of account modal when button clicked:

    $('#example2').on('click', 'tr', function () {         var odata = otable.fngetdata(this);         var pid = odata[0];         $(".modal-footer #pid").val(pid);         //alert(pid);     }); 

the problem facing trying post controller using below form method in modal, how make work:

modal:

        <!-- modal content-->         <div class="modal-content">             <div class="modal-header">                 <button type="button" class="close" data-dismiss="modal">&times;</button>                 <h4 class="modal-title">warning!</h4>             </div>             <div class="modal-body">                 <p>are sure want deactivate account?</p>             </div>             <div class="modal-footer">                 @using (@html.beginform("provideractivate", "adminpanel", formmethod.post))                 {                     <input type="hidden" name="pid" id="pid" value="pid" />                         <input type="submit" value="publish" class="btn btn-default" data-dismiss="modal" />                 }                 @*<button type="button" class="btn btn-default" data-dismiss="modal">ok</button>*@                 <button type="button" class="btn btn-default" data-dismiss="modal">close</button>             </div>         </div>      </div> </div> 

at moment above modal doesnt work. click deactivate (publish) button inside modal , nothing posted controller no account deactivated/activated. if set break point on controller action below , click publish, nothing happens. breakpoint isnt hit.

    public actionresult provideractivate(formcollection form) //change id form post hidden element refer tsprops     {         if (!customsecurity.isadmin(user.identity.name))             return redirecttoaction("index", "home");          string pid = form["pid"];          bool = _db.careproviders.where(c => c.providerid == pid && !c.activated.hasvalue).any();         ....etc 

after discussion op, found having data-dismiss attribute on submit button causing form not post.

this post explains why happens.

you can add hidden field form, assign id hidden, make available in controller action when post controller.

<input type="hidden" name="accountid" id="accountid" val="" /> 

then add line example2 on click function

$('#accountid').val(pid); 

finally, in controller, add parameter controller action called accountid.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -