根据此答案AllowHtml doesn't work with Array,我做了必要的更改以遵循答案,但在将值分配给数组vls.HtmlTexts = form.GetValues(keys[i]);
时出错,“无法将类型string []隐式转换为模型”
StringBuilder output = new StringBuilder();
String[] keys = form.AllKeys;
HtmlValuesCollection vls = new HtmlValuesCollection();
for (int i = 0; i < keys.Length; i++)
{
vls.HtmlTexts = form.GetValues(keys[i]);
for (int j = 0; j < vls.HtmlTexts.Length; j++)
{
output.Append(vls.HtmlTexts[j]);
}
if (i < keys.Length-1)
{
output.Append(",");
}
}
public class HtmlValues
{
[AllowHtml]
public String HtmlText { get; set; }
}
public class HtmlValuesCollection
{
public HtmlValues [] HtmlTexts { get; set; }
}
有何建议?
答案 0 :(得分:1)
您需要将结果转换为所需的实际数组类型
(HtmlValues[])form.GetValues(keys[i]);
因为GetValues的类型不强。