ASP.NET MVC |关于使用jQuery对话框小部件显示模式对话框的问题 [英] ASP.NET MVC | Problem about showing modal dialog using jQuery dialog widget
本文介绍了ASP.NET MVC |关于使用jQuery对话框小部件显示模式对话框的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对ASP.NET MVC和jQuery非常了解.经过一天的尝试,我仍然不知道如何在用户单击链接时使用动作(返回JsonResult)中的数据来弹出jQuery对话框.
I am very fresh to asp.net mvc and jQuery. After one day trying, I still don't know how to pop up a jQuery dialog using data from a action(return JsonResult) while user click a link.
任何建议或指导都值得赞赏.
Any suggest or guideline is appreciate.
谢谢!
推荐答案
Thuntz& RhinoDevX64的回复,终于我解决了.
Thx for Stuntz & RhinoDevX64 's reply, finally I work it out.
jQuery代码:
<script type="text/javascript">
$(function() {
$('.newsitem').click(function() {
var $thisLink = $(this);
$('#dialog').empty();
$.getJSON($thisLink.attr("href"), function(data) {
$('#dialog').html(data.content);
$("#dialog").dialog({
autoOpen: false,
title: data.title,
bgiframe: true,
modal: true,
height: 450,
width: 540,
buttons: {
'关闭': function() {
$(this).dialog('close');
}
}
});
$('#dialog').dialog('open');
});
return false;
});
});
ActionLink
ActionLink
<%= Html.ActionLink(item.Title, "GetByJs", "Article", new { id = item.ID }, new { @class = "newsitem" })%>
操作代码
public ActionResult GetByJs(Guid id)
{
var item = Article.SingleOrDefault(a => a.ID == id && a.AtFront == true);
var jsonData = new { title = item.Title, content = item.BodyContent };
return new JsonResult
{
Data = jsonData
};
}
这篇关于ASP.NET MVC |关于使用jQuery对话框小部件显示模式对话框的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文