无法在自动完成方法中将类型 string 隐式转换为 string[]
下午好——今天是 13 号星期五,所以我当然有一个绝对的母马!!!
下面的代码“应该”创建一个将在文本框自动完成中使用的项目列表。
public string[] GetAutoComplete(string prefixText, int count)
{
try
{
string memberid = HttpContext.Current.Session["VDS_MemberID"].ToString();
string locationid = HttpContext.Current.Session["VDS_LocationID"].ToString();
string inhouse = HttpContext.Current.Session["VDS_Inhouse"].ToString();
string supplier = HttpContext.Current.Session["VDS_Supplier"].ToString();
string groupw = HttpContext.Current.Session["VDS_Group"].ToString();
string external = HttpContext.Current.Session["VDS_External"].ToString();
VDSORDAL.PDC_VDSOREntities autocomplete = new VDSORDAL.PDC_VDSOREntities();
var r = (from p in autocomplete.tblAutoCompletes
where p.MemberId == memberid && p.LocationId == locationid && p.ACItem.Contains(prefixText)
select p);
if (inhouse != "DoNotDisplayInhouse")
r = r.Where(p => p.ACItem == inhouse);
if (supplier != "DoNotDisplaySupplier")
r = r.Where(p => p.ACItem == supplier);
if (groupw != "DoNotDisplayGroup")
r = r.Where(p => p.ACItem == groupw);
if (external != "DoNotDisplayExternal")
r = r.Where(p => p.ACItem == external);
return r.Distinct().OrderBy(p => p.ACItem).ToString();
}
但是,我收到的问题标题是错误的。
谁能建议解决这个问题的方法吗?抱歉..我今天过得很糟糕。
Afternoon all - it's Friday th 13th so of course I am having an absolute mare!!!
The code below, 'should' create a list of items that will be used in a textbox autocomplete.
public string[] GetAutoComplete(string prefixText, int count)
{
try
{
string memberid = HttpContext.Current.Session["VDS_MemberID"].ToString();
string locationid = HttpContext.Current.Session["VDS_LocationID"].ToString();
string inhouse = HttpContext.Current.Session["VDS_Inhouse"].ToString();
string supplier = HttpContext.Current.Session["VDS_Supplier"].ToString();
string groupw = HttpContext.Current.Session["VDS_Group"].ToString();
string external = HttpContext.Current.Session["VDS_External"].ToString();
VDSORDAL.PDC_VDSOREntities autocomplete = new VDSORDAL.PDC_VDSOREntities();
var r = (from p in autocomplete.tblAutoCompletes
where p.MemberId == memberid && p.LocationId == locationid && p.ACItem.Contains(prefixText)
select p);
if (inhouse != "DoNotDisplayInhouse")
r = r.Where(p => p.ACItem == inhouse);
if (supplier != "DoNotDisplaySupplier")
r = r.Where(p => p.ACItem == supplier);
if (groupw != "DoNotDisplayGroup")
r = r.Where(p => p.ACItem == groupw);
if (external != "DoNotDisplayExternal")
r = r.Where(p => p.ACItem == external);
return r.Distinct().OrderBy(p => p.ACItem).ToString();
}
However, I am getting the question title as an error.
Can anyone suggest a way around this? Apologies..I am having a bad day.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
可能
应该是
更新:
听起来这才是你真正的问题。尝试(以下代码是大脑编译的)
我假设
ACItem
是您要返回的字符串,如果不是,请在数组中选择您想要的字符串。或者可能
需要
where p != null
,您非常需要检查 r 并查看其中的内容,但没有足够的信息来最终回答这个问题。也就是说,
.ToArray
而不是.ToString
仍然是您问题的答案,其他任何问题都是不同的问题。Possibly
should be
Update:
Sounds like that's your real problem. Try (following code is brain-compiled)
I'm assuming
ACItem
is the string you want to return, if not, select what you want in the array.Or possibly
the
where p != null
may be necessary, you pretty much need to inspect r and see what's in there, not really enough info to be able to answer this conclusively.That said,
.ToArray
instead of.ToString
is still the answer to your problem, anything else is a different question.最后一行应该是:
The last line should be:
不要执行
ToString()
。使用ToArray()
或ConvertAll().ToArray()
Don't do a
ToString()
. Use eitherToArray()
orConvertAll<string>().ToArray()