asp.net mvc - Passing Id to bootstrap modal popup -


here working after tweak jquery:

$(.modallink").click(function () {      var passedid = $(this).data('id');      $('#id').val(passedid);      $(".modal-body .hiddenid").val(passedid); }); 

//view link

<a href="/home/employee/id=@item.id" data-id="@item.id" data-toggle="modal" data-target="#mymodal">load me</a>  

how capture id i'm passing when <a href click?

so have modal popup , when user clicks want id of when user post data.

view:

@using (html.beginform("employee", "home", formmethod.post)) {      <div class="modal fade" id="mymodal" tabindex="-1" role="dialog" aria-labelledby="mymodallabel" aria-hidden="true">         <div class="modal-dialog">             <div class="modal-content">                 <div class="modal-header">                     <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>                     <h4 class="modal-title" id="mymodallabel">record</h4>                 </div>                 <div class="modal-body">                     <div class="form-group">                         <label for="firstname" class="control-label">first name:</label>                         @html.editor("firstname", new { htmlattributes = new { @class = "form-control" } })                      </div>                     <div class="form-group">                         <label for="lastname" class="control-label">last name:</label>                         @html.editor("lastname", new { htmlattributes = new { @class = "form-control" } })                      </div>                 </div>                 <div class="modal-footer">                     <button type="button" class="btn btn-default" data-dismiss="modal">close</button>                     <button type="submit" class="btn btn-primary">save changes</button>                 </div>             </div><!-- /.modal-content -->         </div><!-- /.modal-dialog -->     </div><!-- /.modal --> } 

controller:

[httppost] public actionresult employee(string id, string firstname, string lastname) {      //more work here..      return view("index"); } 

first need class or can use reference links:

<a href="/home/employee/id=@item.id" data-id="@item.id" data-toggle="modal" data-target="#mymodal" class="modallink">load me</a>  

you need hidden form field hold id submitted form. put in modal form:

@html.hidden("id", "", new { @class = "hiddenid" }) 

then, use javascript. assume jquery work fine you?

$(document).on("click", ".modallink", function () {      var passedid = $(this).data('id');      $(".modal-body .hiddenid").val(passedid); }); 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -