如何将Html.Action附加到jquery [英] How to append an Html.Action to the jquery

查看:103
本文介绍了如何将Html.Action附加到jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以添加

$("#report").html('Html.Action("ReportPage", new { id = Model.GoalId })')

这里的报告是我要放置操作结果的div的id ReportPage id是传递给ReportPage actionresult的参数

here the report is the id of the div where i want to place the result of the action ReportPage id is the parameter passing to the ReportPage actionresult

推荐答案

您需要使用服务器标签才能实现此目的.所以:

You need to use server tags in order to achieve this. So:

$("#report").html('@Html.Action("ReportPage", new { id = Model.GoalId })')

$("#report").html('<%= Html.Action("ReportPage", new { id = Model.GoalId }) %>')

如果这是 操作ReportPage结果 的意思.

if this is what you mean by result of the action ReportPage.

但是,如果通过 操作ReportPage的结果 表示您的MVC操作返回的实际结果(即,视图,json ..),则必须使用类似

But if by result of the action ReportPage you mean the actual result that your MVC action resturns (ie: a view, json ..) you must use something like this

$.get('@Html.Action("ReportPage", new { id = Model.GoalId })', function(data) {
  $("#report").html(data);
});

希望这会有所帮助

PS:请参见 http://api.jquery.com/jQuery.get/有关jQuery.get()的更多详细信息

PS: See http://api.jquery.com/jQuery.get/ on more details regarding jQuery.get()

这篇关于如何将Html.Action附加到jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆