简体   繁体   English

无法将类型string []隐式转换为模型

[英]cannot implicitly convert type string[] to model

depending on this answer AllowHtml doesn't work with Array I did the required changes to follow the answer but getting an error on assign values to array vls.HtmlTexts = form.GetValues(keys[i]); 根据此答案, AllowHtml不适用于Array我做了必要的更改以遵循答案,但在将值分配给数组vls.HtmlTexts = form.GetValues(keys[i]);出错vls.HtmlTexts = form.GetValues(keys[i]); "cannot implicitly convert type string[] to model" “无法将类型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; }
}

Any Advise ? 有什么建议吗?

You need to cast the result to the actual array type you want 您需要将结果转换为所需的实际数组类型

(HtmlValues[])form.GetValues(keys[i]);

as GetValues isn't strongly typed. 因为GetValues的类型不强。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM