我有一个动作结果,我想在我的视图中使用 ajax 将其显示为 div 标签,这是我的动作结果:
public ActionResult Details(string id)
{
var subscriber = new SubscribersModel();
IEnumerable<Subscribe> list = from s in dbcontext.Subscribes select s;
foreach (var sb in list)
{
if (sb.cin == id)
{
subscriber.cin = sb.cin;
subscriber.name = sb.name;
}
}
return PartialView("Details",subscriber);
}
这是我的详细信息视图:
@model _3SDWebProject.Models.SubscribersModel
<fieldset>
<legend>SubscribersModel</legend>
<div class="display-label">
@Html.DisplayNameFor(model => model.name)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.name)
</div>
<div class="display-label">
@Html.DisplayNameFor(model => model.cin)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.cin)
</div>
</legend>
这是我想显示我的操作结果的索引视图:
@model IEnumerable<_3SDWebProject.Models.SubscribersModel>
@{
ViewBag.Title = "Subscribers";
}
<script>
function details(id) {
var url = '/Subscribers/Details/' + id;
$.ajax({
url: url,
type: 'GET',
data: id,
success: function () {
$(".sidebar").html();
}
});
}
$(function () {
$(".details-logo").on('click', function () {
details($(this).attr("DtNo"));
alert("ok");
});
});
</script>
<div class="sidebar">
//Here i want to show my result !!!!!!!
</div>
<div class="content" style="width: 700px; margin-left: 250px; height: 545px;margin-top: -30px;">
<h2>Subscribers</h2>
table class="altrowstable" id="alternatecolor">
<tr>
<th>
CIN
</th>
<th>
Name
</th>
<th>
</tr>
@foreach (var item in Model) {
<tr id="row-@item.cin">
<td>
@Html.DisplayFor(modelItem => item.cin)
</td>
<td>
@Html.DisplayFor(modelItem => item.name)
</td>
</tr>
//this is my actionLink
@Html.ActionLink("Details", "Details", new { id = item.cin }, new { @class = "details-logo",@DtNo=item.cin})
}
所以如果有人有任何想法,我将不胜感激。注意:当我按下我的详细信息操作链接时,它会给我真实的信息,但不是在我的侧边栏中,而是在一个单独的视图中,如下所示: