javascript - ASP.Net MVC 5 Passing data to modal -


i need pass object modal. have :

 @for (int = 0; < @model.count; i++) {     <div id="contentdiv" style="margin: 10px">         <div class="form-group">             <div>                 day : @model[i].day.day / hour : @model[i].hour             </div>             <div class="form-group">                  <button id="reservationbutton" class="btn-default btn-lg" disabled="@model[i].ishourtaken()" onclick="@($"openmodalpopup('{i}')");">book</button>             </div>         </div>     </div> } 

my js :

   function openmodalpopup(id) {     $('#mymodal').modal(); }; 

and modal :

<div class="modal fade" id="mymodal" tabindex="-1" role="dialog"  aria-labelledby="mymodallabel"> <div class="modal-dialog" role="document">     <div class="modal-content">         <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">book hour!</h4>         </div>         <div class="modal-body">             <div>                 <div>                     <div class="row">                         <b>day:</b>                         <div class="col-lg-5">                             <span class="reservationday"> @model[indexoftheday].day </span>                         </div>                     </div>                     <div class="row">                         <b>hour:</b>                         <div class="col-lg-5">                             <span class="reservationhour"> @model[indexoftheday].hour </span>                         </div>                     </div> (......) 

my problem here @model[indexoftheday].day dont know how pass indexoftheday modal.

thanks in advance!

thank sir! managed :

<button id="reservationbutton" class="btn-default btn-lg" disabled="@model[i].ishourtaken()" onclick="@($"openmodalpopup('{@model[i].getday()}')");">book</button> 

js:

 function openmodalpopup(reservationday ) {     $('.reservationday').text(reservationday);     $('#mymodal').modal(); }; 

and in modal

<div class="modal-body">             <div>                 <div class="container-fluid">                     <div class="row">                         <div class="col-xs-3">                             <b>day</b>                         </div>                         <div class="col-xs-9">                             <span class="reservationday"/>                         </div>                     </div> 

unfortunatelly next problem faced reason (error : constant value expected...) can't pass 2 parameters function :( updated function looks :

  function openmodalpopup(reservationday,reservationhour ) {         $('.reservationday').text(reservationday);         $('.reservationhour').text(reservationhour);         $('#mymodal').modal();     }; 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -