问题:我想要做的是在我退出添加到视图的文本框时触发表单提交事件。
详细信息:我在 MVC 应用程序中有一个视图,我在视图底部添加了三个文本框。在此添加之前,我有一个 Html 帮助器文本区域,当我退出时触发 this.form.submit:
<%=Html.TextAreaFor(r => r.Notes, new { @class = "textAreaNoScroll", @onblur = "this.form.submit();"} })%>
在更改之前,这是页面底部的最后一个控件。我已经剪切了代码@onblur ...并将其粘贴到现在,最后一个控件是什么:
<%=Html.TextBoxFor(acc => acc.AccountNumber, new { @onblur = "this.form.submit();"}) %>
但是当我现在调试时,视图仍然会在 id 为“r.Notes”的文本区域上提交。
修复:首先,我从浏览器(Chrome)检查“查看源代码”中的标记。更改是正确的。我清除了浏览器缓存,但这没有任何区别。这是相关的代码段:
<asp:Panel ID="pnlProcessingInstructions" runat="server">
<table class="displayBox-topBottom">
<tr>
<td class="labels displayInput_noWidth">Processing Notes</td>
<td class="labels displayInput_noWidth">Instructions</td>
</tr>
<tr>
<%if (Model != null && Model.PaymentDayId != -1)
{ %>
<td><%=Html.TextAreaFor(r => r.ProcessingNotes, new { @class = "textAreaNoScroll" })%></td>
<%}
else
{%>
<td><%=Html.TextAreaFor(r => r.ProcessingNotes, new { @class = "textAreaNoScroll" })%></td>
<%}%>
<td><%=Html.TextAreaFor(r => r.Notes, new { @class = "textAreaNoScroll" })%></td> <!-- FORMER LAST CONTROL -->
</tr>
<tr>
<td><span id = "ProcessingCharsLeft" class="smallerFont">1,000</span> characters left</td>
<td><span id = "CharsLeft" class="smallerFont">1,000</span> characters left</td>
</tr>
</table>
</asp:Panel>
</fieldset>
<fieldset>
<legend class="labels"> Payment Details</legend>
<asp:Panel ID="pnlPaymentDetails" runat="server">
<table class="displayBox-topBottom">
<tr>
<td class="labels displayInput_noWidth">Institution</td>
<td class="labels displayInput_noWidth">Transit</td>
<td class="labels displayInput_noWidth">Account Number</td>
</tr>
<tr>
<td><%=Html.TextBoxFor(i => i.Institution) %></td>
<td><%=Html.TextBoxFor(tr => tr.TransitNumber) %></td>
<td><%=Html.TextBoxFor(acc => acc.AccountNumber, new { @onblur = "this.form.submit();"}) %></td> <!-- NEW LAST CONTROL -->
</tr>
</table>
</asp:Panel>
它永远不会超过 'r.Notes' 并且表现得好像 'this.form.submit' 仍然是控件的一部分。同样,我已经清除了缓存并重建了我的解决方案。'this.form.submit()' 如何在代码不存在的控件上触发?