【发布时间】:2020-06-09 02:06:57
【问题描述】:
我需要在我的 html 表中查看 ajax 成功消息 我的cshtml代码是:
@*@{Customer.Models.Customers cust = ViewBag.Customers;
}*@
@{
}
<center><h1 style="color:red">User details</h1></center>
<div>
<table class="table">
<tr>
<td>ID</td>
<td>res.Id</td>
</tr>
<tr>
<td>FIRST NAME</td>
<td>res.Fname</td>
</tr>
<tr>
<td>LAST NAME</td>
<td>res.Lname</td>
</tr>
<tr>
<td>LOCATION</td>
<td>res.Location</td>
</tr>
<tr>
<td>Contact</td>
<td>res.Contact</td>
</tr>
<tr>
<td>Email</td>
<td>res.Email</td>
</tr>
<tr>
<td>Password</td>
<td>res.Password</td>
</tr>
<tr>
<td>Role</td>
<td>res.Category</td>
</tr>
<tr>
</table>
</div>
@section Scripts{
<script>
$.ajax({
contentType: "application/json",
type: "GET",
url: "https://localhost:44397/api/Values/Details/" + id,
success: function (data) {
alert('Welcome!');
res = data;
// window.location.href = "/Home/Details/" + data.id;
},
error: function (jqXHR, textStatus, errorThrown) {
$("#postResult").val(jqXHR.statusText);
}
});
</script>
}
有没有办法使用成功数据传入每个表行? 也就是说,我希望 res 存储成功数据,然后将其传递给 res.Fname 等表字段(例如),它应该相应地显示数据。
【问题讨论】:
-
你需要单独在一列或多列中显示值
-
我需要在对应的列中显示每个值
-
如果您使用剃须刀页面,repo 和 demo 可以为您提供帮助。基本上有一个局部视图呈现主剃须刀页面内的 ajax 部分。该项目依赖于具有 ajax 支持的自定义 PagingTagHelper。
-
你有两个项目,一个 web 项目和一个 web api 吗?是不是想在web项目中使用ajax调用web api项目中的方法,然后在web项目中显示返回值?
-
@XueliChen 我有一个解决方案,其中包含 2 个控制器 api 和 home。我想要的只是将我的家庭控制器动作控件转换为我的 ajax 视图。但我无法在我的 html 表中获得该值。
标签: javascript html ajax asp.net-core asp.net-ajax