我目前正在运行一个问题,当我去一个页面并点击我的一个按钮时,我得到一个页面无法显示错误信息。我意识到因为我有多个提交按钮,当我点击一个按钮时它不知道要点什么。这是我目前拥有的按钮:
<button class="glossyBtn" type="submit" name="submitButton" value="@Html.Encode(Kids.Resources.Message.Ok)">
<img alt="" style="vertical-align: middle; margin-right:1px" src="@Url.Content("~/Content/blueprint/plugins/buttons/icons/tick.png")" />
<span style="vertical-align: middle">Ok</span>
</button>
这就是我在.cshtml页面中的内容:
@using (Html.BeginForm("Manage", "Invoice"))
{
<fieldset id="contentView">
<div class="row">
@Html.Raw(Html.DatePickerEnable())
<fieldset>
<span>@Kids.Resources.Entities.Billing.BillingStatus</span> @Html.EditorFor(m => m.BillingStatuses)
<br />
<div style="float:left; width:320px">
<span>Begin Date</span> @Html.EditorFor(m => m.BeginDate) @Html.ValidationMessageFor(m
=> m.BeginDate)
<span>End Date</span> @Html.EditorFor(m => m.EndDate) @Html.ValidationMessageFor(m
=> m.EndDate)
<div style="background-color: white;" class="bubble">@Html.ValidationSummary(true, Message.ValidationErrorSummary, new { @class = "error" })</div>
</div>
<button class="glossyBtn" type="submit" name="submitButton" value="@Html.Encode(Kids.Resources.Message.Ok)">
<img alt="" style="vertical-align: middle; margin-right:1px" src="@Url.Content("~/Content/blueprint/plugins/buttons/icons/tick.png")" />
<span style="vertical-align: middle">Ok</span>
</button>
</fieldset>
</div>
@if (Model.Invoices != null)
{
<div class="row">
@Html.Grid(Model.Invoices).Attributes(id => "Invoices").Columns(column =>
{
column.For(i => i.CanAddItems ? string.Format(
"<a class='noStyle' href='{0}' title='Edit'><img src='{1}'/></a>",
Url.Action("Prepare", "Invoice", new { invoiceId = i.InvoiceId }),
Url.Content("~/Content/images/pencilEdit.png")) : string.Empty).Sortable(false).Encode(false);
column.For(i => i.CanPay ? string.Format(
"<a class='noStyle' href='{0}' title='Pay'><img class='pic' src='{1}'/></a>",
Url.Action("Pay", "Invoice", new { invoiceId = i.InvoiceId }),
Url.Content("~/Content/images/moneySign.png")) : string.Empty).Sortable(false).Encode(false);
column.For(i => i.CanVoid ? string.Format(
"<a class='noStyle' href='{0}' title='Void'><img class='pic' src='{1}'/></a>",
Url.Action("Void", "Invoice", new { invoiceId = i.InvoiceId }),
Url.Content("~/Content/images/newVoid.png")) : string.Empty).Sortable(false).Encode(false);
if (Kids.Common.KidsSettings.Settings.SubmissionInvoice)
{
column.For(i => i.CanSubmit ? string.Format(
"<a class='noStyle' href='{0}' title='{2}'><img class='pic' src='{1}'/></a>",
Url.Action("Files", "PaymentVoucherFile", new { invoiceId = i.InvoiceId }),
Url.Content("~/Content/images/newVoucher.png"), Kids.Resources.Ocr.PaymentVoucherFile) : string.Empty).Sortable(false).Encode(false);
}
}).Empty(string.Format("No {0}", Kids.Resources.Entities.Billing.Invoices)).Sort(Model.GridSortOptions)
<p />
我在整个网站上看了一下,我发现的东西似乎有点太多了。是否有一些简单的东西,我可以在同一页面上做,如javascript或其他东西,而不是更改两个或三个文件。
Prepare - Pay - Void也是包含相同结构且具有相同提交按钮的表单。
答案 0 :(得分:0)
如果您有许多不同表单的提交按钮,那么在javascript中使用以下内容:
var form = $(document.forms ['formName'])//或使用像$这样的索引(document.forms [0]
然后form.submit();这些按钮需要onclick动作并输入='button'
希望这有帮助