我的部分观点存在问题。我有两个部分视图正确加载,一切正常。但是在form.submit上,无论用户点击什么按钮,都只触发一个函数。我在@html.beginform上设置了一个id,但它似乎无法正常工作!
HTML:
<div class="tab-content">
<div class="fade in active hidden" id="reconiliation">
@Html.Partial("UploadReconciliationFile")
</div>
</div>
<div class="tab-content">
<div class="" id="payment">
@Html.Partial("UploadBankgiroFiles")
</div>
</div>
UploadReconciliationFile部分查看
<div id="reconciliationdiv" class="hidden">
@using (Html.BeginForm("UploadReconciliationFile", "Payments", FormMethod.Post, new { id = "UploadReconciliationFile", @class = "merchant-form" }))
{
<div class="left-col">
<div class="form-group">
@if (Model.Installations.Any())
{
@Html.LabelFor(model => model.Installations, new { @class = "h4" })
@Html.DropDownListFor(model => model.Id, Model.Installations, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Installations, "", new { @class = "text-danger" })
}
</div>
</div>
<div class="form-button">
<div class="btn btn-primary" id="fileUploadDiv">
<input type="file" name="files" class="hidden" multiple="multiple" id="file" onchange=" form.submit() " />
<label for="file" id="fileLabel">Välj filer</label>
</div>
</div>
}
UploadBankgiroFiles部分视图
<div id="bankgirodiv">
@using (Html.BeginForm("UploadBankgiroFiles", "Payments", FormMethod.Post, new { id = "UploadBankgiroFiles", @class = "merchant-form" }))
{
<div class="left-col">
<div class="form-group">
@if (Model.Installations.Any())
{
@Html.LabelFor(model => model.Installations, new { @class = "h4" })
@Html.DropDownListFor(model => model.Id, Model.Installations, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Installations, "", new { @class = "text-danger" })
}
</div>
</div>
<div class="form-button">
<div class="btn btn-primary" id="fileUploadDiv">
<input type="file" name="files" class="hidden" multiple="multiple" id="file" onchange="form.submit() " />
<label for="file" id="fileLabel">Välj filer</label>
</div>
</div>
}
我的代码有任何建议和改进吗?
答案 0 :(得分:0)
它在提交按钮上使用了不同的id:s。
<div id="bankgirodiv">
@using (Html.BeginForm("UploadBankgiroFiles", "Payments", FormMethod.Post, new { id = "UploadBankgiroFiles", @class = "merchant-form" }))
{
<div class="left-col">
<div class="form-group">
@if (Model.Installations.Any())
{
@Html.LabelFor(model => model.Installations, new { @class = "h4" })
@Html.DropDownListFor(model => model.Id, Model.Installations, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Installations, "", new { @class = "text-danger" })
}
</div>
</div>
<div class="form-button">
<div class="btn btn-primary" id="fileUploadDiv">
<input type="file" name="files" class="hidden" multiple="multiple" id="files" onchange="form.submit() " />
<label for="files" id="fileLabel">Välj filer</label>
</div>
</div>
}