我对 MVC 完全陌生。我想创建一个 Viewbag 来包含控件的选定索引。我可以在我的 .ascx 文件中设置它吗?或者捕获这些信息的最佳方式是什么?
<select id="accounttype" style="float: left;" autocomplete="off">
<%
if (Request.Url.AbsolutePath.ToUpper().StartsWith("/COMMERCIAL")) //Commercial
{
%>
<option value="C" selected="selected">eManager+</option>
<option value="C">Retirement Plans</option>
<option value="C">Brokerage Accounts</option>
<%
}
else if (Request.Url.AbsolutePath.ToUpper().StartsWith("/BUSINESS")) //Business
{
%>
<option value="B" selected="selected">eManager+</option>
<option value="B">Business Credit Card</option>
<option value="B">Retirement Plans</option>
<option value="B">Brokerage Accounts</option>
<%
}
else //Personal, root or other
{
%>
<option value="P" selected="selected">Online Banking</option>
<option value="P">Health Savings Account</option>
<option value="P">Paychek Plus!®</option>
<option value="P">Gift Cards</option>
<option value="P">Business Tax Manager</option>
<option value="P">Business Card Manager</option>
<option value="P">Business Credit Card</option>
<%
}
%>
</select>