asp.net - Using (Preferably) C# Razor or JQuery to find which button opened the modal and setup modal dynamically -
so have modals similar in our asp.net mvc project , want set them dynamically don't have have many files strewn on place.
once i've clicked button , opened modal how check button opened modal can custom logic , inject specific html?
button #1 :
<a class="btn btn-primary margin-bottom-5" data-toggle="modal" data-target="#newbugmodal"> <i class="fa fa-lg fa-fw fa-plus"></i> new bug </a> <div class="modal fade" id="newbugmodal" tabindex="-1" role="dialog" aria-labelledby="newbugmodallabel" aria-hidden="true"> @html.partial("_bugmodal") </div>
button #2 :
<a href="#" class="btn btn-default" data-toggle="modal" data-target="#bugeditmodal"> edit </a> <div class="modal fade" id="bugeditmodal" tabindex="-1" role="dialog" aria-labelledby="bugeditmodallabel" aria-hidden="true"> @html.partial("_bugmodal") </div>
customizeable modal :
<div class="modal-dialog demo-modal"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> × </button> <!-- custom logic here (this set bug edit or new bug)--> <h4 class="modal-title">bug edit || new bug</h4> </div> <div class="modal-body"> <div class="row"> <div class="col-md-12"> <div class="form-group"> <!-- custom logic here (this set prefilled text or placeholder text)--> <textarea class="form-control" id="bug" rows="5" required>specific bug error</textarea> </div> </div> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-primary"> save changes </button> </div> </div><!-- /.modal-content --> </div>
i know simple can't quite put finger on , whether or not should using jquery accomplish or razor code. thoughts?
you try passing button selector id partial, :
@html.partial("_bugmodal", new viewdatadictionary { { "buttonid", "you-button-id"} });
in partial add hidden field this:
<input type='hidden' id='some-id' value='@viewbag.buttonid'/>
Comments
Post a Comment