نمایش ایجکسی یک partial view در popover بوت استرپ 3
نویسنده: وحید نصیری
تاریخ: ۱۳۹۴/۱۲/۱۶ ۲۳:۳۰
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
public ActionResult RenderResults(string param1)
{
var users = new[]
{
new User{ Id = 1, Name = "Test 1", Rating = 3},
new User{ Id = 2, Name = "Test 2", Rating = 4},
new User{ Id = 3, Name = "Test 3", Rating = 5}
};
return PartialView("_RenderResults", model: users);
} @using RemotePopOver.Models
@model IList<User>
<ul id="ratings1" data-title="Ratings" class="list-unstyled">
@foreach (var user in Model)
{
<li>
@user.Name
<span class="badge pull-right">@user.Rating</span>
</li>
}
</ul> <span id="remotePopover1"
aria-hidden="true"
data-param1="test"
data-popover-content-url="@Url.Action("RenderResults", "Home")"
class="glyphicon glyphicon-info-sign btn btn-info"></span> @section Scripts
{
<script type="text/javascript">
$(document).ready(function () {
$('body').on('mouseenter', 'span[data-popover-content-url]', function () {
var el = $(this);
$.ajax({
type: "POST",
url: $(this).data("popover-content-url"),
data: JSON.stringify({ param1: $(this).data("param1") }),
contentType: "application/json; charset=utf-8",
dataType: "json",
// controller is returning a simple text, not json
complete: function (xhr, status) {
var data = xhr.responseText;
if (status === 'error' || !data) {
el.popover({
content: 'Error connecting server!',
trigger: 'focus',
html: true,
container: 'body',
placement: 'auto',
title: 'Error!'
}).popover('show');
}
else {
el.popover({
content: data,
trigger: 'focus',
html: true,
container: 'body',
placement: 'auto',
title: $('<html />').html(data).find('#ratings1:first').data('title')
}).popover('show');
}
}
});
}).on('mouseleave', 'span[data-popover-content-url]', function () {
$(this).popover('hide');
});
});
</script>
}