在我的 ASP.NET MVC 應用程式中,有一個包含主要請求型別的組合框。
當用戶更改組合框值時,顯示和隱藏與其相關的部分視圖。
我想知道每個區域視圖都包含按鈕,當它單擊時,包含在區域視圖中加載。那么在更改組合框值時有什么方法可以做到這一點,默認情況下我想加載包含加載。我可以像區域視圖一樣加載它,但是對于這個程式,有必要單擊按鈕,因為用戶單擊的每個區域視圖都帶有來自控制器的參考編號。
這是組合框的編碼方式。
<div class="form-group row">
@Html.LabelFor(model => model.ReqType, htmlAttributes: new { @class = "control-label col-md-3" })
<div class="col-sm-8">
@Html.DropDownListFor(model => model.ReqType, ReqTypes, "Select Request Type", new { @class = "js-dropdown", id = "ReqType" })
@Html.ValidationMessageFor(model => model.ReqType, "", new { @class = "text-danger" })
</div>
</div>
這就是我根據組合框選定值隱藏和顯示部分視圖的方式
$('#ReqType').change(function () {
if ($(this).val() == '1') {
$('#pnlPurchaseEmp').show();
$('#pnlPurchaseItem').show();
$('#pnlGeneralItms').hide();
$('#pnlSuspenseDetails').hide();
$('#SusMain').empty();
$('#PayVMain').empty();
$('#ReqSettle').empty();
$('#PayVExpen').empty();
$('#PayBill').empty();
$('#PayBillS').empty();
}
}
所以這是包含加載部分的部分視圖,作為一個例子,如果combobox value ==1然后 $('#pnlPurchaseEmp').show();這個將顯示并且這個按鈕在那里,所以當 $('#pnlPurchaseEmp').show();這個開始顯示時我也想觸發這個addAnotherEmp按鈕
<fieldset id="pnlPurchaseEmp" style="display:@(Model.PurchasingEmpList == null || Model.PurchasingEmpList.Count == 0 ? " none" : "" )">
<ul id="RequEmp" style="list-style-type: none"> @if (Model != null && Model.PurchasingEmpList != null) { foreach (Asp_PASMVC.Models.PurchasingEmpl Emp in Model.PurchasingEmpList) { Html.RenderPartial("_PurchaseEmployees", Emp); } } </ul>
<button type="button" id="addAnotherEmp" class="btn btn-info" href="#">Add New Record</button>
<script type="text/javascript">
$(function() {
$("#addAnotherEmp").click(function() {
$.get('/AppRequests/PurchaseEmpList', function(template) {
$("#RequEmp").append(template);
});
});
});
</script>
<br />
</fieldset>
uj5u.com熱心網友回復:
試試這個
$('#ReqType').change(function () {
if ($(this).val() == '1') {
$('#pnlPurchaseEmp').show(0,
function() {// show with callback function
$('#addAnotherEmp').trigger('click');
});
}
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/478982.html
標籤:javascript C# html jQuery
下一篇:如何在跨度和輸入之間同步輸入?
