将多个值附加到a<;表>;使用JavaScript
我在MVC视图中有一个表 以下是HTML代码:将多个值附加到a<;表>;使用JavaScript,javascript,jquery,asp.net-mvc,Javascript,Jquery,Asp.net Mvc,我在MVC视图中有一个表 以下是HTML代码: <table class="table" > @{int rowNo = 0;} <tr> <td data-toggle="modal" data-target="#newAppointment" style="height: 40px; width: 40px; background: red;"> <img style="object-fit:
<table class="table" >
@{int rowNo = 0;}
<tr>
<td data-toggle="modal" data-target="#newAppointment" style="height: 40px; width: 40px; background: red;">
<img style="object-fit: cover;" src='@Url.Content("~/Images/plus.png")'/>
</td>
</tr>
<tr style="background: white">
<th></th>
<th style="font-size: 20px; text-align: center;color:#1d69b4;">
Date of birth
</th>
<th style="font-size: 20px; text-align: center;color:#1d69b4;">
Last Name
</th>
<th style="font-size: 20px; text-align: center;color:#1d69b4;">
First Name
</th>
<th style="font-size: 20px; text-align: center;color:#1d69b4;">
Kasse
</th>
<th style="font-size: 20px; text-align: center;color:#1d69b4;">
Last visit
</th>
<th style="font-size: 20px; text-align: center;color:#1d69b4;">
Last edit
</th>
<th></th>
</tr>
<tbody id="patients">
@foreach (var item in Model)
{
<tr>
<td class="point">
@(rowNo += 1)
</td>
<td class="title">
@Html.DisplayFor(modelItem => item.Date_of_Birthday)
</td>
<td class="title">
@Html.DisplayFor(modelItem => item.Last_name)
</td>
<td class="title">
@Html.DisplayFor(modelItem => item.First_name)
</td>
</tr>
}
</tbody>
</table>
@{int rowNo=0;}
出生日期
姓
名字
卡斯
最后一次访问
最后编辑
@foreach(模型中的var项目)
{
@(行号+=1)
@DisplayFor(modelItem=>item.Date\u of\u生日)
@DisplayFor(modelItem=>item.Last_name)
@DisplayFor(modelItem=>item.First\u name)
}
我还有一个AJAX脚本将值附加到表中:
<script>
$('#search').click(function () {
$("#patients").empty();
var lname = $("#lname").val();
var model = {
LastName: lname
};
$.ajax({
url: '@Url.Action("ResultOfSearch", "PatientDatabase")',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(model),
type: 'POST',
dataType: 'json',
processData: false,
success: function(data) {
var list = data;
//alert(list);
var listnumber = 0;
for (var i = 0; i <= list.length - 1; i++) {
var patientsList = ' <td class="point">' +
listnumber +
1 +
'</td>' +
'<td class="title"> ' +
list[i].dateOfBirthday +
'</td>' +
'<td class="title"> ' +
list[i].lastName +
'</td>' +
'<td class="title"> ' +
list[i].firstName +
'</td>';
$("#patients").append(patientsList);
};
}
});
});
</script>
$(“#搜索”)。单击(函数(){
$(“#患者”).empty();
var lname=$(“#lname”).val();
var模型={
姓氏:lname
};
$.ajax({
url:'@url.Action(“ResultoSearch”、“PatientDatabase”),
contentType:'application/json;charset=utf-8',
数据:JSON.stringify(模型),
键入:“POST”,
数据类型:“json”,
processData:false,
成功:功能(数据){
var列表=数据;
//警报(列表);
var-listnumber=0;
对于(var i=0;i附加tr
更改追加
代码,如下所示
$("#patients").append('<tr>'+patientsList+'</tr>');
$(“#患者”)。追加(“”+patientsList+“”);