我想准备内容并在点击按钮时打印它。但我有错误。
index.cshtml:
If (UseImageSearch(x,y,"Image.PNG")) {
SendLeftClick(x,y); // send left mouse click to the x,y of the founded image
}
layout.cshtml:
@{
ViewBag.Title = "Home Page";
}
<button>Get External Content</button>
<br />
<div id="printForm">
</div>
<script>
$(document).ready(function () {
$('button').click(function (e) {
$.ajax({
type: "POST",
url: '@Url.Action("MyPartialView")',
data: {
'p': "xxx"
},
success: function (result) {
$('#printForm').empty();
$('#printForm').html(result);
$('#printForm').print();
},
error: function (xhr, ajaxOptions, thrownError) {
// bu kısımda eğer ajax işlemi başarısız ise
// hata mesajı verebiliriz.
alert(xhr.responseText);
}
});
});
});
</script>
控制器:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My ASP.NET Application</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
<script src="//kendo.cdn.telerik.com/2016.2.504/js/jquery.min.js"></script>
<script src="//kendo.cdn.telerik.com/2016.2.504/js/kendo.all.min.js"></script>
<script src="~/Scripts/jQuery.print.js"></script>
</head>
<body>
@RenderBody()
</body>
</html>
MyPartialView.cshtml:
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult MyPartialView(string p=null)
{
return PartialView();
}
如果我评论打印方法它工作正常。但<span id="manchego"></span>
<script>
jQuery(document).ready(function () { //here is error: Uncaught ReferenceError: jQuery is not defined
$("#manchego").kendoBarcode({
value: "2346722",
type: "ean8",
width: 280,
height: 100
});
});
</script>
无效。
错误:未捕获的ReferenceError:未定义jQuery
我不必使用jquery.print.js。我该如何打印局部视图?