C# foreach 循环不拾取字符串

问题描述

我有一个“foreach”循环迭代一个列表,但由于某种原因它不会选择其中一个字符串值。有问题的字符串是:

<p>@extractedCaptions[10]</p> 提供准确的字符串 = "Photo to be displayed on the Voice website with your Feedback. If possible,please attach a relevant photo from the project/study i.e. a picture of the research team,equipment etc,or the project/study logo."

所以我有一个 foreach 循环,其中之一:

}
else if (cap == "Photo to be displayed on the Voice website with your Feedback. If possible,or the project/study logo.")
{

它不会接听。有谁知道是什么原因造成的?所有其他字符串都可以正常拾取。

编辑 - 完整代码

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage

@using Umbraco.Forms.Core
@using Umbraco.Forms.Data.Storage
@using Voice.BL.Extensions
@using Voice.BL.Helpers
@using System.Web.Script.Serialization;

@{
    Layout = "AdminMaster.cshtml";

    var currentMemberCollaborationGroup = MemberHelper.GetCurrentMemberCollaborationGroup();
    if (currentMemberCollaborationGroup == null)
    {
        var loginNode = VNHelper.GetLoginNode();
        Response.Redirect(loginNode.Url() + "?returnUrl=" + Url.Encode(Request.Url.PathAndQuery),true);
        return;
    }

    var opportunityId = Request.QueryString["opId"].NullSafetoInt();
    var record = FeedbackHelper.GetFeedbackRecordFromOpportunityId(opportunityId);
    var FeedbackFormUrl = string.Format("{0}://{1}{2}",Request.Url.Scheme,Request.Url.Authority,"?altTemplate=OpportunityFeedbackForm&opportunityId=" + opportunityId);

    var opportunity = Umbraco.TypedContent(opportunityId);

    if (opportunity.GetPropertyValue<int>("collaborationGroup") != currentMemberCollaborationGroup.Id)
    {
        Response.Redirect("/dashboard/opportunities/");
    }
}


<section class="c-section">
    @Html.Partial("CollaboratorActivityMenu",Voice.BL.Enums.CollaboratorActivityMenuSelection.Opportunities)
    <div class="o-container">
        <h1>@opportunity.Name</h1>
        @Html.Partial("CollaboratorOpportunityMenu",Model)
    </div>

    <div class="o-container">
        <div class="o-row">
            <div class="o-col o-col--auto@md">
                <h2>Feedback</h2>
            </div>

            @if (record != null)
            {
                <div class="o-col--auto@md u-text-right">
                    @Html.Partial("FeedbackProcess",new ViewDataDictionary { { "OpportunityId",opportunityId } })
                </div>
            }
        </div>

        @if (record != null)
        {
            var extractedFields = new List<keyvaluePair<string,string>>();
            var newOrderFields = new List<keyvaluePair<string,string>>();
            var extractedCaptions = new List<string>();
            foreach (var field in record.RecordFields)
            {
                var extractValue = field.Value.ValuesAsstring().NullSafetoString();
                var extractType = CGHelper.CleanString(field.Value.Field.FieldType.Name).ToLower();
                var extractCaption = field.Value.Field.Caption;
                extractedFields.Add(new keyvaluePair<string,string>(extractType,extractValue));
                extractedCaptions.Add(extractCaption);
            }

            var count = 0;
            foreach (var cap in extractedCaptions.ToList())
            {
                if (cap == "Opportunity ID")
                {
                    extractedCaptions.Remove(cap);
                    extractedCaptions.Insert(0,cap);
                    var keyOld = extractedFields[count].Key;
                    var valueOld = extractedFields[count].Value;
                    newOrderFields.Add(new keyvaluePair<string,string>(keyOld,valueOld));
                }
                else if (cap == "Name")
                {
                    extractedCaptions.Remove(cap);
                    extractedCaptions.Insert(1,valueOld));
                }
                else if (cap == "Project/Study Title")
                {
                    extractedCaptions.Remove(cap);
                    extractedCaptions.Insert(2,valueOld));
                }
                else if (cap == "Project/Study Overview")
                {
                    extractedCaptions.Remove(cap);
                    extractedCaptions.Insert(3,valueOld));
                }
                else if (cap == "How were Voice members involved?")
                {
                    extractedCaptions.Remove(cap);
                    extractedCaptions.Insert(4,valueOld));
                }
                else if (cap == "How did Voice members help/influence your project?")
                {
                    extractedCaptions.Remove(cap);
                    extractedCaptions.Insert(5,valueOld));
                }
                else if (cap == "Project/Study Outcomes/Findings")
                {
                    extractedCaptions.Remove(cap);
                    extractedCaptions.Insert(6,valueOld));
                }
                else if (cap == "What will happen next with your research?")
                {
                    extractedCaptions.Remove(cap);
                    extractedCaptions.Insert(7,valueOld));
                }
                else if (cap == "Have any papers or reports been published as a result of the research project?")
                {
                    extractedCaptions.Remove(cap);
                    extractedCaptions.Insert(8,valueOld));
                }
                else if (cap == "If yes,please upload a copy here")
                {
                    extractedCaptions.Remove(cap);
                    extractedCaptions.Insert(9,valueOld));
                }
                else if (cap == "Photo to be displayed on the Voice website with your Feedback. If possible,or the project/study logo.")
                {
                    extractedCaptions.Remove(cap);
                    extractedCaptions.Insert(10,valueOld));
                }
                else if (cap == "If further project information is available,please provide the link below")
                {
                    extractedCaptions.Remove(cap);
                    extractedCaptions.Insert(11,valueOld));
                }
                count++;
            }
        }
        else
        {
            <p>This opportunity has not received any Feedback yet.</p>
        }

        <p><strong>Feedback form URL:&nbsp;</strong><a href="@FeedbackFormUrl" target="_blank">@FeedbackFormUrl</a></p>
    </div>
</section>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)