我在部分视图中弹出一个回发时没有工作。我正在使用jquery ajax,当我单击表中的用户记录时,部分视图正在调用。
以下是我将调用点击部分视图的代码。
<td><a href="#" class="details" data-id="@item.TeamId" data-dialogmodalbind=".dialog_content3">
@Html.DisplayFor(modelItem => item.Description)</a>
</td>
这是我的代码,我调用局部视图
<div id="detailsPlace" class="dialog_content3" style="display:none">
</div>
这是我的jquery代码
<script type="text/javascript">
$(function ()
{
$('.details').click(function ()
{
var $buttonClicked = $(this);
var id = $buttonClicked.attr('data-id');
$.ajax(
{
url: '@Url.Action("Details","Team")',
type: "POST",
dataType: "html",
data: { id: id },
success: function (partialView)
{
//event.preventDefault();
$('#detailsPlace').html(partialView);
}
});
});
});
</script>
这是我的部分视图
@model App.ViewModels.ViewDetailTeam
@using App.Helpers
@{HtmlHelpers.getDynamicLabels(Model.DynamicLabel);}
<div class="dialogModal_header"> @Model.TeamDetails.TeamName</div>
<div class="dialogModal_content">
<div class="main-content">
<div class="navi-but">
<a href="#"><span class="previous">Previous</span></a>
<a href="#"><span style="padding-right:7px">Next</span><span class="next"></span></a>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><img src="Images/settings.png" /> </a>
<ul class="dropdown-menu" role="menu">
<li><a href="@Url.Action("Edit", "Team", new { id = Model.TeamDetails.TeamId })">Edit</a></li>
<li><a href="@Url.Action("Delete", "Team", new { id = Model.TeamDetails.TeamId })">Delete</a></li>
</ul>
</li>
</div><br /><br />
<div style="float:left;margin-top:15px;">
@Html.CustomLabel("lblTeam","CT Team Name:")
</div>
<div style="margin-top:15px; margin-left:115px;">
@Model.TeamDetails.TeamName
</div>
<div style="float:left;margin-top:15px;">
@Html.CustomLabel("lblDescription","Description:")
</div>
<div style="margin-top:15px; margin-left:115px;">
@Model.TeamDetails.Description
</div>
<div style="float:left;margin-top:15px;">@Html.CustomLabel("lblCTUserCount","User Count:") </div>
<div style="margin-top:15px; margin-left:115px;">
@Model.TeamDetails.UserCount
</div>
</div>
</div>
控制器
public ActionResult Details(int id)
{
Session[ApplicationConstants.CurrentPageId] = 111;
FlightCoreModel.User loggedInUser = new FlightCoreModel.User();
int PageId = Convert.ToInt16(Session[ApplicationConstants.CurrentPageId]);
if (Session[ApplicationConstants.UserModel] != null)
{
loggedInUser = (FlightCoreModel.User)Session[ApplicationConstants.UserModel];
}
if (loggedInUser.UserId > 0)
{
ViewDetailTeam viewDetailTeam = new ViewDetailTeam(FlightDbContext, loggedInUser.UserId, PageId);
ViewData["DetailModel"] = viewDetailTeam;
viewDetailTeam.Retrieve(id);
return PartialView("_TeamDetails", viewDetailTeam);
//return View(viewDetailTeam);
}
else
{
return RedirectToAction("SignIn", "Account", new { area = "" });
}
}
答案 0 :(得分:0)
更改下面的javascript。这将帮助您访问由ajax函数获取的html代码。
$(document).on('click','.details', function () {
{
var $buttonClicked = $(this);
var id = $buttonClicked.attr('data-id');
$.ajax(
{
url: '@Url.Action("Details","Team")',
type: "POST",
dataType: "html",
data: { id: id },
success: function (partialView)
{
//event.preventDefault();
$('#detailsPlace').html(partialView);
}
});
});