當我在下拉列表中選擇調整時,我可以獲取值,但是當呈現正確的表單時,表單中的下拉UI沒有正確的值。它幾乎可行,但我覺得我沒有正確地做jquery。在視圖中,我有兩種不同的表單,我使用Jquery根據下拉選擇選擇要顯示的表單。根據MVC和Jquery中的下拉選擇隱藏或顯示特定形式
繼承人JQUERY
$(document).ready(function() {
$("#adjustments").hide();
$(".TypeClass").change(function() {
var selected = $(".TypeClass option:selected").text();
alert(selected);
if (selected == "Received") {
$("#received").show();
$("#adjustments").hide();
}
if (selected == "Adjustment") {
$("#adjustments").show();
$("#received").hide();
}
});
$(".TypeClass2").change(function() {
var selected = $(".TypeClass2 option:selected").text();
alert(selected);
if (selected == "Received") {
$("#received").show();
$("#adjustments").hide();
}
if (selected == "Adjustment") {
$("#adjustments").show();
$("#received").hide();
}
});
});
繼承人的VIEW
<div id="received">
<fieldset>
<legend>New Inventory Transaction</legend>
<table>
<tr><td>@Html.LabelFor(model => model.ItemName)</td><td>@Html.DisplayFor(model => model.ItemName)</td></tr>
<tr><td>@Html.LabelFor(model => model.ItemNumber)</td><td>@Html.DisplayFor(model => model.ItemNumber)</td></tr>
<tr><td>@Html.LabelFor(model => model.XactTypeId)</td><td>@Html.DropDownListFor(model => model.XactTypeId, (SelectList)ViewData["InvType"], "Choose Type", new { @class = "TypeClass" })</td></tr>
<tr><td>@Html.LabelFor(model => model.XactTotalCost)</td><td>@Html.EditorFor(model => model.XactTotalCost)</td></tr>
<tr><td></td><td><p> <input type="submit" value="Create" /></p></td></tr>
</table>
</fieldset>
</div>
<div id="adjustments">
<fieldset>
<legend>New Inventory Transaction</legend>
<table>
<tr><td>@Html.LabelFor(model => model.ItemName)</td><td>@Html.DisplayFor(model => model.ItemName)</td></tr>
<tr><td>@Html.LabelFor(model => model.ItemNumber)</td><td>@Html.DisplayFor(model => model.ItemNumber)</td></tr>
<tr><td>@Html.LabelFor(model => model.WharehouseName)</td><td>@Html.EditorFor(model => model.WharehouseName)</td></tr>
<tr><td></td><td><p> <input type="submit" value="Create" /></p></td></tr>
</table>
</fieldset>
</div>
你正面臨什麼問題? –
在UI部分進行測試時,下拉列表與我設置的ALERTS不匹配。是否有一些jquery,將允許我設置它像這樣在C#dropdownlist1.SelectedValue =「myValue」 –