【发布时间】:2012-11-08 12:33:03
【问题描述】:
我可以添加吗
$("#report").html('Html.Action("ReportPage", new { id = Model.GoalId })')
这里的报告是我要放置动作结果的 div 的 id ReportPage id 是传递给 ReportPage actionresult 的参数
【问题讨论】:
标签: jquery asp.net-mvc
我可以添加吗
$("#report").html('Html.Action("ReportPage", new { id = Model.GoalId })')
这里的报告是我要放置动作结果的 div 的 id ReportPage id 是传递给 ReportPage actionresult 的参数
【问题讨论】:
标签: jquery asp.net-mvc
您需要使用服务器标签来实现这一点。所以:
$("#report").html('@Html.Action("ReportPage", new { id = Model.GoalId })')
或
$("#report").html('<%= Html.Action("ReportPage", new { id = Model.GoalId }) %>')
如果这就是您所说的ReportPage 操作的结果。
但是,如果 ReportPage 操作的结果 是指 MVC 操作返回的实际结果(即:视图、json ..),则必须使用类似这个
$.get('@Html.Action("ReportPage", new { id = Model.GoalId })', function(data) {
$("#report").html(data);
});
希望对你有帮助
PS:有关 jQuery.get() 的更多详细信息,请参阅 http://api.jquery.com/jQuery.get/
【讨论】:
这样,你的action html将在主页面加载后被ajax加载。
css
.support {display: hidden;}
html
<div class="support">
<div class="report-page">
<a href="Url.Action("ReportPage", new { id = Model.GoalId })" />
</div>
</div>
js
var url = $('.support .report-page a').prop('href');
$.get(url, null, function(html){
$('#report').html(html);
}, html);
或者,如果你只想要一个 http 请求,你可以这样做:
css
.support {display: hidden;}
html
<div class="support">
<div class="report-page">
@Html.Action("ReportPage", new { id = Model.GoalId })
</div>
</div>
js
var html = $('.support .report-page').html();
$('#report').html(html);
【讨论】: