Asp.net | STAThread属性错误

时间:2012-09-19 09:25:56

标签: asp.net-mvc vb.net razor

我想在MVC razor(VB)语法中点击按钮打开FolderBrowseDialog。

为此我在“onclick”按钮事件上调用jquery函数,并通过该函数我在我的控制器中发出一个Post请求,其中包含显示FolderBrowseDialog的代码。

这是我的代码。

HTML:

<input type="button" class="btn" value="browse" onclick="SelectFolder()"/>

jquery的:

<script type="text/javascript">


function SelectFolder()
{
    $.post("@Url.Action("FolderPicker", "Home")", function () {
            alert('sdd');
        },function(ex){
            alert("Error occured in AJAX");  
    });
}


</script>

Controller .. vb代码显示FolderBrowserDialog。

<STAThreadAttribute()>
Sub FolderPicker()
    Dim browser As FolderBrowserDialog = New FolderBrowserDialog()
    browser.Description = "Select Folder"
    browser.ShowNewFolderButton = False
    browser.RootFolder = Environment.SpecialFolder.Desktop
    Dim result As DialogResult = browser.ShowDialog()

    If result = DialogResult.OK Then
        Dim selectedPath As String = browser.SelectedPath
    End If


End Sub

目前     昏暗的结果As DialogResult = browser.ShowDialog() 我正在异常

Current thread must be set to single thread apartment (STA) mode before OLE  

calls can be made. Ensure that your Main function has STAThreadAttribute  

marked on it. This exception is only raised if a debugger is attached to the  

process.  

我还包括STATreadAttribute()和STATread()但仍然出现此错误。

我错过了什么吗? 还有其他办法吗?

2 个答案:

答案 0 :(得分:0)

STATreadAttribute应该在程序的Main函数上,这意味着程序的入口点

答案 1 :(得分:0)

ASP.NET / MVC中没有FolderBrowseDialog 您可以阅读更多内容here