Razor 新手,尝试转换以下内容:
<select id="Province" name="Province" style="width: 235px; background-color: #FFFFCC;">
<%
string[] provinces = ViewBag.ProvincesForSelectedCountry;
string selectedProvinceName;
if (Model != null && !String.IsNullOrEmpty(Model.Province))
selectedProvinceName = Model.Province;
else
selectedProvinceName = ConfigData.DefaultProvinceName;
foreach (var anEntry in provinces)
{
string selectedTextMark = anEntry == selectedProvinceName ? " selected=\"selected\"" : String.Empty;
%>
<option value="<%= anEntry %>" <%= selectedTextMark %>>
<%= anEntry %></option>
<%
}
%>
</select>
</td>
剃须刀:
<select id="Province" name="Province" style="width: 235px; background-color: #FFFFCC;">
@string[] provinces = ViewBag.ProvincesForSelectedCountry;
string selectedProvinceName;
if (Model != null && !String.IsNullOrEmpty(Model.Province))
selectedProvinceName = Model.Province;
else
selectedProvinceName = ConfigData.DefaultProvinceName;
foreach (var anEntry in provinces)
{
string selectedTextMark = anEntry == selectedProvinceName ? " selected=\"selected\"" : String.Empty;
<option value="@anEntry" @selectedTextMark>
@anEntry</option>
}
</select>
</td>
我收到此错误:
Invalid expression term 'string' in @string[] provinces = viewBag.ProvincesForSelectedCountry;
提前致谢。