C# 如何在mvc中使用OpenFileDialog
我的代码在下面C# 如何在mvc中使用OpenFileDialog,c#,asp.net,.net,asp.net-mvc,C#,Asp.net,.net,Asp.net Mvc,我的代码在下面 @Ajax.ActionLink("Choose File", "chooseItemView", new { }, new AjaxOptions { UpdateTargetId = "re
@Ajax.ActionLink("Choose File",
"chooseItemView",
new { },
new AjaxOptions
{
UpdateTargetId = "replaceDiv",
InsertionMode = InsertionMode.Replace,
HttpMethod = "GET",
//OnBegin = "startPreLoader",
OnSuccess = "stopPreLoader",
OnFailure = "stopPreLoader"
}, new
{
@id=1,
@type="file",
@class="btn btn-primary offset-top-2",
/*@id=item.GetHashCode().GetHashCode(),
* onclick = "fileUploadFunction('" + item.GetHashCode().GetHashCode() + "')"*/
onclick = "fileUploadFunction('" + 1 + "')"
})
public ActionResult chooseItemView()
{
/*MessageBox.Show("Hi");*/
OpenFileDialog openFileDialog=new OpenFileDialog();
openFileDialog.Multiselect = false;
openFileDialog.Filter = "txt files (*.txt)|*.txt| DOC files (*.doc)|*.doc";
openFileDialog.ShowDialog();
return PartialView("_UploadItemView",null);
}
按如下方式运行时,有一个选项
在进行OLE调用之前,必须将当前线程设置为单线程单元STA模式。确保主函数上标记了STAThreadAttribute。只有将调试器附加到进程时,才会引发此异常
那么我该如何解决这个问题呢?您不能在mvc web应用程序中使用openfiledialog。 改用 请参阅此可能的副本