asp.net - How can i use OpenFileDialog in C# mvc -
my code below
@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); }
there exceoption when run below
"current thread must set single thread apartment (sta) mode before ole calls can made. ensure main function has stathreadattribute marked on it. exception raised if debugger attached process."
so how can solve this?
you can't use openfiledialog in mvc web application. instead use
<input type="file"/>
refer openfiledialog in cshtml
Comments
Post a Comment