How do I need to show the Selected Account in the Dropdownlist box using Asp.net mvc
I have this code in my View..
<tr><td>Account:</td><td><%=Html.DropDownList("drdAccounts",Model.AccountsListHeader),Model.selectedAccount,"Select Account", new { onchange = "JavaScript:AccountChanged()" })%><span class="requiredAsterisk">*</span></td></tr>
But I am getting Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1002: ; expected
is that I am doing something wrong in this line? How to s开发者_StackOverflow中文版how the Selected account on the Dropdown list box? Thanks
You have a closing parenthesis that you need to remove:
<%= Html.DropDownList("drdAccounts", Model.AccountsListHeader,
Model.selectedAccount, "Select Account",
new { onchange = "JavaScript:AccountChanged()" }
) %>
This being said I would recommend you using the strongly typed DropDownListFor helper method to generate dropdown lists:
<%= Html.DropDownListFor(x => x.selectedAccount, Model.AccountsListHeader,
"Select Account", new { id = "accounts" }) %>
And then use jquery to attach a change event handler unobtrusively:
$(function() {
$('#accounts').change(function() {
// TODO: do something when the current value changes
});
});
精彩评论