【问题标题】:How can i use OpenFileDialog in C# mvc我如何在 C# mvc 中使用 OpenFileDialog
【发布时间】:2015-06-01 06:49:45
【问题描述】:

我的代码在下面

 @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) 模式。确保您的 Main 函数上标记了 STAThreadAttribute。只有在将调试器附加到进程时才会引发此异常。”

那我该如何解决呢?

【问题讨论】:

标签: c# asp.net .net asp.net-mvc


【解决方案1】:

您不能在 mvc Web 应用程序中使用 openfiledialog。 而是使用

<input type="file"/>

参考这个OpenFileDialog in cshtml

【讨论】:

    猜你喜欢
    • 2011-02-16
    • 1970-01-01
    • 2016-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多