Ajax上傳文件至MVC的controller
<!--這一行是假的filebox 用於呈現選取的File --> < input id = "false_fileBox" name = "false_fileBox" placeholder = "點此選擇檔案" type = "text" /> <!--這一行是被隱藏起來的真filebox,用css將opacity(不透明度)設為0,再用margin(外邊距)給調整到與上方的textbox重疊的位置--> < input id = "fileBox" name = "fileBox" onchange = "inFalseFilebox(this,'false_fileBox')" style = "margin-top: -27px; margin-bottom: 8px; width: 100%; opacity: 0;" type = "file" class = "file" /> <!--上傳按鈕,會用他來觸發檔案上傳的事件--> < button type = "button" onclick = "fileUpload('fileBox')" > 上傳 </ button > 紅色這段應該也可以直接使用 <input id= " file " type= " file " > 直接呈現 甚至不需要Onchange就可以呈現目前選取的資料名稱 //第一個是在真的filebox中設定onchange //讓真的filebox接收到檔案時,可以同步把檔案路徑名稱放進假的textbox中 //不然真的filebox被隱藏了,使用者也無法看到自己選擇了哪個檔案。 function inFalseFilebox ( obj,id ) { $( '#' +id).val(obj.value);...