gpt4 book ai didi

javascript - ASP.Net MVC 5 将数据传递给模态

转载 作者:行者123 更新时间:2023-11-30 15:03:33 25 4
gpt4 key购买 nike

我需要将对象传递给我的模式。现在我有这样的东西:

 @for (int i = 0; i < @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>
}

我的代码:

   function OpenModalPopUp(id) {
$('#myModal').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 this 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> (......)

我的问题在这里 @Model[indexOftheDay].Day 我不知道如何将 indexOftheDay 传递给我的模式。

提前致谢!

最佳答案

谢谢楼主!我设法做到了:

<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();
};

在我的模式中

<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>

不幸的是,我面临的下一个问题是出于某种原因(错误:预期为常数值...)我无法将两个参数传递给我的函数 :( 我更新后的函数如下所示:

  function OpenModalPopUp(reservationDay,reservationHour ) {
$('.reservationDay').text(reservationDay);
$('.reservationHour').text(reservationHour);
$('#myModal').modal();
};

关于javascript - ASP.Net MVC 5 将数据传递给模态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46139484/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com