[英]Handle onclick event for partial view buttons
I have in a page more partial views
rendered. 我在页面中呈现了更多的
partial views
。 This is how the page looks: 页面外观如下:
I need to handle to onclick
event for the button Create Invoice 我需要处理“创建发票”按钮的
onclick
事件
<div class="row">
<div class="button-bar col-md-2">
@Html.ActionLink(@Resources.Common.ShowInvoice, "EditLotDamage", "TimberMonitor", new { Id = 0, LotId = ViewBag.Id }, new { @class = "btn btn-success" })
</div>
<div class="button-bar col-md-2">
@Html.ActionLink(@Resources.Common.CreateInvoice, "EditLotDamage", "TimberMonitor", new { Id = 0, LotId = ViewBag.Id }, new { @id = "InvoiceDamageButton", @class = "btn btn-success", onclick = "validate" })
</div>
</div>
The buttons are on a partial view
with name: LotDamageButtonBarPartial
, which is rendered from another partial view like this: 这些按钮位于名称为
LotDamageButtonBarPartial
的partial view
上,该视图是从另一个局部视图呈现的,如下所示:
........
tabDamage.SetContent(() =>
{
if (ViewBag.CanModify)
{
Html.RenderPartial("LotDamageButtonBarPartial");
}
Html.RenderAction("LotDamageListPartial", new { LotId = ViewBag.Id });
});
........
I have tried to handle the onclick event like this in the main page: 我试图在主页上处理类似onclick的事件:
$(document).ready(function () {
$('#InvoiceDamageButton').click(function ()
{
alert("test");
});
});
but it is not working. 但它不起作用。 Can you advise?
你能建议吗?
When you are creating InvoiceDamageButton
button, you are also defining an onclick handler for it here: onclick = "validate"
. 当创建
InvoiceDamageButton
按钮时,您还在此为其定义onclick处理程序: onclick = "validate"
。
I don't know the code of validate()
but it is probably stoping event propagation and the event never triggers your jQuery function. 我不知道
validate()
的代码,但它可能正在停止事件传播,并且该事件从未触发您的jQuery函数。
Check if there's a e.stopPropagation();
检查是否有一个
e.stopPropagation();
inside function validate, if there is then remove this line. 内部函数验证(如果有),然后删除此行。 Also, check if
validate()
is returning false
and if it is, change that too (either don't return anything or return true). 另外,请检查
validate()
是否返回false
,如果是,也进行更改(不返回任何内容或返回true)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.