2
我試圖用所選項目信息(屬性)更新文本框。我可以得到選擇的項目名稱而不是Id,或者換句話說,如何在javascript中選擇一個項目然後將其設置爲txtbox時,如何獲取ViewData中的Whats的屬性?使用javascript選擇列表框項目時更新文本框的信息
@Html.ListBox("ListBoxName", new SelectList((IEnumerable<Epic>)ViewData["selectedestimate"], "Id", "Name", "EstimatedTime"), new {@class = "ListBoxClass", @style = "height: 325px;"})
@Html.TextBoxFor(model => model.Name, new {@class = "TimeClass"})
<script type="text/javascript">
$(function() {
$(".ListBoxClass").click(function (event) {
var selectedid = $(this).find("option:selected").val();
// get items properties and info so that the value can be set to a textbox
//set textbox value to Name of selected Value
$(".TimeClass").val(selectedid);
event.preventDefault(); // Stop the browser from redirecting as it normally would
$.get('@Url.Action("UserStoriesList", "Estimate")', { id: selectedid }, function (result) {
$('#stories').html(result);
});
});
});
</script>