获取@html.隐藏值
Getting @html.hidden value
我正在尝试从我的变量中获取值。
@Html.Hidden("myVar", 0);
此变量将根据我单击的链接进行更新
<script type="text/javascript">
$(document).ready(function () {
$(".resend").click(function (){
$('#myVar').val(this.id);
console.log(document.getElementById('myVar').value);
$("#myModal").modal('show');
});
});
</script>
然后,此 JavaScript 将调用弹出模型。
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!— Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Confirmation</h4>
</div>
<div class="modal-body">
<p>Are you sure you want to resend the registration link to the patient?</p>
</div>
<div class="modal-footer">
<a href='@Url.Action("TherapistResendLinkToPatient", "Account", new { pid = I WANT TO CHANGE THIS TO THE VARIABLE #myVar })' style="text-decoration:none;">
<input type="button" class="btn btn-primary" value="Confirm" />
</a>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
我想在我的弹出框中更改 pid = #myVar,但我不知道如何插入值。任何人都知道我如何将我的 pid 引用为 #myVar?
谢谢
为此,插入值的最佳方法是每次更改 #myVar 时更新 href
属性,使用 .attr() 包含新的值 #myVar。执行此操作的一个例子是在javascript
中添加:
$('#confirmButton').attr('href','@Url.Action("TherapistResendLinkToPatient", "Account", new { pid = '+document.getElementById('myVar').value+' })');
您还需要在按钮周围的 href 包装器中添加一个 id,如下所示:
<a href='@Url.Action("TherapistResendLinkToPatient", "Account", new { pid = '+document.getElementById('myVar').value+' })' style="text-decoration:none;" id="confirmButton">
<input type="button" class="btn btn-primary" value="Confirm" />
</a>
我希望这有所帮助
如果我理解您的要求,下面应该能够提供帮助。
目标是在数据目标标记中设置数据,然后在单击按钮时读取该数据。您的 ASP.NET 视图页面需要一个 forloop 我假设它已经存在,因为它从数据库创建用户列表。下面我假设您可以填写一些数据。
MVC View Page.CSHTML
@model PROJECT.Models.PatientRESEND
<table class="table table-striped">
<thead>
<th>Patient Name</th>
<th>Patient Email</th>
<th>Actions</th>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>@item.FirstName</td>
<td>@item.LastName</td>
<td><button data-target="@item.PatientID|@item.FirstName @item.LastName" id="resend" class="resend">Send Link</button></td>
</tr>
}
</tbody>
</table>
然后使用 jQuery 和 Bootstrap 向医生显示信息。
$(document).ready(function () {
$(".resend").click(function (event){
event.preventDefault();
var patientid = $(this).data("target").split('|')[0];
var patientName = $(this).data("target").split('|')[1];
$("#myModal").find('.name').text(patientName);
var resethref = $("#myModal").find('.resendLink').attr('href');
resethref = resethref+patientid;
$("#myModal").find('.pid_output').text("Link: "+resethref);
$("#myModal").find('.resendLink').attr("href", resethref);
$("#myModal").modal('show');
});
});
<td><button data-target="@item.PatientID|@item.FirstName @item.LastName" id="resend" class="resend">Send Link</button></td>
上面的代码将患者 ID 和患者名称由 | 分隔,然后我们使用 jQuery 来解析和更新引导模式的 DOM 对象。
请参阅JSFiddle的完整工作示例https://jsfiddle.net/fcrvz0gk/
我的团队设法解决了这个问题。
<script type="text/javascript">
function DisableButton(b) {
document.getElementById("cancel").disabled = true;
b.disabled = true;
b.form.submit();
}
$(document).ready(function () {
$(".resend").click(function () {
var id = this.id;
$("#sendLink").attr('href', '/Account/TherapistResendLinkToPatient?pid=' + id);
$("#myModal").modal('show');
});
});
</script>
我们不是存储变量,而是通过Javascript调用该方法。
感谢您的所有帮助,真的很感激!
相关文章:
- 如何使用JavaScript在没有html dom的情况下隐藏html元素
- Javascript/jQuery赢得't隐藏HTML元素
- 隐藏HTML元素中的JSON编码和解码
- 如何比较单元格值和隐藏 html 表中的行
- 只有当类是硬编码的时,才可以使用jQuery来显示/隐藏html内容
- 隐藏html页面中的某些字段以用于打印布局中的页眉/页脚
- 如何在Android 4.3及更早版本上隐藏HTML元素
- Javascript:显示/隐藏HTML节点
- 为什么这个Javascript没有隐藏HTML项目
- 隐藏HTML表单's“提交”按钮
- 使用jquery显示/隐藏html ul
- 显示几秒钟后隐藏 HTML 元素
- 如何隐藏 HTML 按钮
- 如何显示和隐藏 html 字段集 以及从 Asp.Net 代码后面设置图例文本
- 我可以根据换行动态隐藏 html 字符吗?
- 在所选选项更改时显示和隐藏 html 元素
- 多个文本字段,根据单选选择显示/隐藏(Html,JS)
- 在用户提交之前隐藏 HTML 元素
- 通过单击按钮数组获取隐藏 html 元素值的当前数组
- 如何通过MVC操作方法显示/隐藏HTML按钮