我创建了一个保存文件的控制器.
以下代码是该控制器的一部分:
if ( Request.Files.Count != 0 ) {
HttpFileCollectionBase files = Request.Files;
foreach ( HttpPostedFileBase file in files ) {
if ( file.ContentLength > 0 ) {
if ( !file.ContentType.Equals( "image/vnd.dwg" ) ) {
return RedirectToAction( "List" );
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在ASPX页面很简单:
<input type="file" name="file" />
<input type="file" name="file" />
...// many inputs type file
Run Code Online (Sandbox Code Playgroud)
问题是foreach因为它返回一个错误(我知道因为我在调试模式下运行并在foreach语句中放置了断点):
Unable to cast object of type 'System.String' to type 'System.Web.HttpPostedFileBase'.
Run Code Online (Sandbox Code Playgroud)
我的错是什么?
我有3个具有相同来源的下拉列表2,第3个具有所选列表.如果选中的列表不为null,我应该从第一个中删除选定项,并在第三个中绑定.第二个是静态的,显示原始列表.
但我无法弄清楚如何在一个物体中前进.
错误:foreach语句不能对'object'类型的变量进行操作,因为'object'不包含'GetEnumerator'的公共定义
public void DataSource(object source, object select, string Value = "UId", string Text = "Text")
{
ddlThis.DataSource = source;
ddlThis.DataTextField = Text;
ddlThis.DataValueField = Value;
ddlThis.DataBind();
ddlThisHidden.DataSource = source;
ddlThisHidden.DataTextField = Text;
ddlThisHidden.DataValueField = Value;
ddlThisHidden.DataBind();
if (select != null)
{
ddlOther.DataSource = select;
ddlOther.DataTextField = Text;
ddlOther.DataValueField = Value;
ddlOther.DataBind();
foreach (var item in ddlOther.DataSource)
ddlThis.Items.Remove(item);
}
}
Run Code Online (Sandbox Code Playgroud)
版本2
public void DataSource(IList source, IList select, string Value = "UId", string Text = "Text")
{
ddlThis.DataSource = source; …Run Code Online (Sandbox Code Playgroud) 大家好,我有这个给定的表..在其中我想要一个选择查询来将 managerid 替换为与其关联的员工的姓名。
例如:我想要输出为
1 | 安迪| SW |安迪
2 | 布里吉| SW |安迪
3 | 托比 | sw |brij
是否可以在同一个表中执行此操作。