我想在 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
在 Dim 结果 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() 但我仍然收到此错误。
我错过了什么吗?还有其他方法吗?