我需要使用for循環,我想我可以訪問數組中每一行中的每個屬性來組成我的字符串。字符串使用「foreach」或「for」構造數組使用「foreach」或「for」循環構造
public static string GetHintText(this IEnumerable<UserTrainingPointsDataModel> HintTextString)
{
foreach (var part in HintTextString)
{
HintText = HintText + " " + part.Name + " " + part.IncentiveTrainingModuleOptionName + " = " + part.Points;
}
return HintText;
}
public class UserTrainingPointsDataModel
{
public virtual int InteractionType { get; set; }
public virtual int Points { get; set; }
public virtual string Name { get; set; }
public virtual string IncentiveTrainingModuleOptionName { get; set; }
}
每一行constains值:
China Incentive Program Points For Completing = 50
India - Q2 Incentive Points Per Correct Answer = 50
China - Q2 Incentive Points For Completing = 50
India Incentive Program Points Per Correct Answer = 100
India - Q2 Incentive Points Per Correct Answer = 100
HintTextString
包含每個5行以上的性能,我需要補的字符串,看起來像這樣:
"Incentive Program: " + part.Name[0] + " " + part.IncentiveTrainingModuleOptionName[0] + " + " + part.Points[0] +
"Incentive Program: " + part.Name[1] + " " + part.IncentiveTrainingModuleOptionName[1] + " + " + part.Points[1]
等。所以我需要一個for循環呢?以及如何獲得HintTextString的長度? IntelliSense不給我這個屬性
的觀點:
<% if (module.HasAssessment)
{ %>
<div class="<%: moduleStateClass %>"> </div>
<div class="<%: moduleScoreClass %>"><%: module.ModuleScore %></div>
<% var HintText = TrainingModuleProgressStateDataModelExtentions.GetHintText(module.UserTrainingPoints); %>
<script type="text/javascript">
<%: Html.GetQTip("training-module-id-" + module.TrainingModuleId , "Incentive program: " + HintText , "training-module-id-" + module.TrainingModuleId , Zinc.Web.Extensions.QTipPosition.Bottom, true, "Module Points") %>
</script>
<% } %>
<% else
{ %>
<% var HintText = TrainingModuleProgressStateDataModelExtentions.GetHintText(module.UserTrainingPoints); %>
<script type="text/javascript">
<%: Html.GetQTip("training-module-id-" + module.TrainingModuleId , "Incentive program: " + HintText ,"training-module-id-" + module.TrainingModuleId , Zinc.Web.Extensions.QTipPosition.Bottom, true, "Module Points") %>
</script>
<% } %>
「行動」:
<div class="module-column-content">
<% Html.RenderPartial("~/Areas/Training/Views/Home/Details.ascx", Model); %>
</div>
感謝
所以你要爲一個刺痛返回整個列表 –
後產生的結果 – Jared
也發佈視圖如果可能的話 – Jared