2012-09-19 41 views
0

我想打開一個FolderBrowseDialog上按鈕單擊MVC剃鬚刀(VB)的語法。Asp.net | STAThread屬性錯誤

爲此,我在「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> 

控制器.. 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 

在 昏暗的結果的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(),但仍然我得到這個錯誤。

我是否缺少一些東西? 有沒有其他方法可以做到這一點?

回答

0

FolderBrowseDialog不可用ASP.NET/MVC的切入點。
您可以閱讀更多內容here

0

的STATreadAttribute應該在你的程序的主要功能,這意味着該方案

+0

我正在製作一個Web應用程序,所以它沒有任何主要方法。 –

+0

嘗試將頁指令的 上的AspCompat屬性設置爲true <%@ Page AspCompat =「true」%> – meirrav