剃刀代码意外错误

时间:2017-10-23 11:51:52

标签: razor

我有以下代码:

@{

    string url = "xxxxxx"; 
    WebClient wc = new WebClient(); 
    var json = (JObject)JsonConvert.DeserializeObject(wc.DownloadString(url));
    var items = json["STORIES"];
    var noOfItems = items.Count();
    var rowEnd = "</div><div class='row'>";

    if (items.Count() > 0) {

    @*Create a list of divisions from the divisions in the JSON data. Start with a blank list and loop through each item adding its division to the list if its not there already.*@

    List<string> itemDivisions = new List<string>();

    for(var i = 0; i < noOfItems; i++) {
        var itemDivision = items[i]["person"]["division"].ToString();

        if(!itemDivisions.Contains(itemDivision)){
            itemDivisions.Add(itemDivision);
        }

    }

    List<string> itemFilters = new List<string>();

    for(var i = 0; i < noOfItems; i++) {
        var itemFilter = items[i]["person"]["filter"].ToString();

        if(!itemFilters.Contains(itemFilter)){
            itemFilters.Add(itemFilter);
        }

    } 
  @*Loop through the Divisions list to print all the options for the select box*@

var noOfDivisions = itemDivisions.Count();
<div class="bg-black filter-bar">
    <div class="container">
    <p>Filter Our Stories</p>
    <div class="select-wrap">
        <select class="filter-division filter-stories-select" data-results-container="filterResults" data-filter-attr="currentDivision">
            <option value="all">All Divisions</option>
            @for(var count = 0; count < noOfDivisions; count++) {
                <option value="@itemDivisions[count]">@itemDivisions[count]</option>
            }
        </select>
    </div>
</div>

    ...

我添加此内容的那一刻:

List<string> itemFilters = new List<string>();

for(var i = 0; i < noOfItems; i++) {
    var itemFilter = items[i]["person"]["filter"].ToString();

    if(!itemFilters.Contains(itemFilter)){
        itemFilters.Add(itemFilter);
    }

} 

我收到以下错误消息:

enter image description here

0 个答案:

没有答案