【发布时间】:2012-05-31 10:06:35
【问题描述】:
我正在尝试使用按钮连接到控制器中的方法。我可以通过此链接进行连接:
@Html.ActionLink("Print", "Print", new { id = Model.SalesContractId})
但我不想要一个链接,我想要我的对话框上的按钮来完成它。我尝试了以下方法:
$('#btnDialogPrint').click(function () {
location.href = '<%= Url.Action("Print", "Print", new { id = Model.SalesContractId}) %>';
});
但它只是将我重定向到显示错误请求的页面。
namespace Contract.Controllers
{
public class ContractController : Controller
{
CompassEntities db = new CompassEntities();
public ActionResult Print(int id)
{
return View(""); // This can be removed and Print code may be added
}
不要担心里面的代码,一旦我进入这个方法,我就会得到。
我可以在这里附上一个链接吗?
<input type="button" value="Print" id="btnDialogPrint" />
我的视图 Edit.cshtml
@model Contract.Models.tbSalesContract
<!DOCTYPE html>
<html>
<head>
<title>Edit Contract</title>
</head>
<!-- Script section -->
<script src="@Url.Content("~/Scripts/Views/Contract.js")" type="text/javascript"></script>
<!-- Templates -->
<script id="tmplDebtorList" type="text/x-jquery-tmpl">
<div class="DebtorResults">
<span><div style="width:80px;float:left;">${CustomerAccNo}</div></span><span><a href="#" class="debtorLink" value="${DebtorId}">${CustomerName}</a></span>
</div>
</script>
<body>
@using (Html.BeginForm("Edit", "Contract", FormMethod.Post, new { id = "frmMain",name="frmMain" }))
{
【问题讨论】:
-
我认为您应该在事件处理程序中进行 AJAX 获取!
-
$.ajax({ url: '@Url.Action("Print","Contract", new {id = Model.SalesContractId})' });这不起作用以太
-
@daveL 你能看看我的 ajax 事件并告诉我我做错了什么
-
你忽略了返回结果..看看api.jquery.com/jQuery.get
标签: c# jquery asp.net-mvc asp.net-mvc-3 razor