0
新剃刀,試圖轉換如下:MVC 4 ASPX剃刀
<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;
在此先感謝。
感謝安德魯,現在我發現了另一個錯誤:@Dictionary countryCodeNamePairs = ViewBag.CountryCodeNameDictionary;字符串是無效的表達! –
hncl
2012-04-27 06:03:40
再次嘗試使用大括號。 – 2012-04-27 06:18:33
再次感謝安德魯。 – hncl 2012-04-27 06:30:09