在 MVC 4 应用程序中,我希望在单击链接时在灯箱中显示一些相关的产品列表。我有方法返回我需要的产品:
public ActionResult GetRelatedProducts(int id)
{
var realProducts = GetRelatedProducts(id);
List<object> productsObjectList = new List<object>();
foreach (var item in realProducts)
{
productsObjectList .Add(new
{
id = item.Id,
fullname = item.Name
});
}
return Json(productsObjectList , JsonRequestBehavior.AllowGet);
}
HTML是:
<a class="show" id="show">Show</a>
<div id="productBox" style="display: none;">
// Product list will get here
</div>
和脚本:
$('#show').click(function (e) {
url = '@Url.Action("GetRelatedProducts", "Product")';
var data = { id: '@Model.Id' };
$.post(url, data, function (result) {
$('#productBox').lightbox_me({
onLoad: function () {
//How to send returned product list to light box, to show them by foreach loop
}
});
e.preventDefault();
});
});
我如何发送产品列表 productBox
来展示产品?