因此,我试图获得一个非常简单的ajax调用来工作,但始终会遇到上述错误。
视图:(@ model ...位于布局上方)
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
<script>
function DownloadPDF() {
$.ajax({
type: "POST",
url: "/Editor/MailMergeVorlage",
data: { tmpGutschein = @Model }
})
};
</script>
</head>
...
<body>
...
<section>
<a href="#!" onclick="DownloadPDF()">
<img src="~/Content/images/Icon_Word.png" style="max-width:64px;max-height:64px;" />
</a>
</section>
</body>
控制器:
public void MailMergeVorlage(DefType tmpGutschein)
{
Editor editor = new Editor();
editor.CreatePDF(tmpGutschein);
}
我尝试过的事情
@Scripts.Render("~/bundles/jquery")
更新:下面的工作代码。
查看:body标签内的代码不是head
<script>
function DownloadPDF() {
$.ajax({
type: "POST",
url: "/FE/MailMergeVorlage",
data: { tmpGutschein: @Html.Raw(Json.Encode(Model)) }
})
};
</script>
控制器:
[HttpPost]
public void MailMergeVorlage(DefType tmpGutschein)
{
Editor editor = new Editor();
editor.MailMergeVorlage(tmpGutschein);
}
答案 0 :(得分:0)
首先,您需要在标题标签中添加jquery脚本。 写入后,body标签中的功能不在标题标签中,如下代码
@{ Layout = null; }
<!DOCTYPE html>
<html>
<head>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
</head>
...
<body>
...
<section>
<a href="#" onclick="DownloadPDF()">
<img src="~/Content/images/Icon_Word.png" style="max-width:64px;max-height:64px;" />
</a>
</section>
<script>
function DownloadPDF() {
$.ajax({
type: "POST",
url: "/Editor/MailMergeVorlage",
data: @Html.Raw(Json.Encode(Model));
sucess:function(result){
alert(result);
}
})
};
</script>
</body>