0
我是vb編程新手,一直在嘗試實現上傳表單以將文件上傳到我的網絡服務器。我使用.vbhtml和VB。我創建了表單,但是當我點擊提交按鈕「Button1_Click」時,沒有任何反應。這裏是我的代碼上傳表單(.vbhtml)和VB控制器
---- Index.vbhtml代碼-----在HomeController.vb使用
@Code
ViewData("Title") = "Home Page"
End Code
<form id="form1" runat="server" action="">
<div>
<input type="file" ID="FileUpload1" runat="server" /><br />
<br />
<input type="button" ID="submit_button" runat="server" OnClick="Button1_Click"
value="Upload File" /> <br />
<br />
<span id="Span1" runat="Server" />
</div>
</form>
-------- --------代碼-----------
Public Class HomeController
Inherits System.Web.Mvc.Controller
Dim Span1 As Object
Dim FileUpload1 As Object
'Upload file
Public Sub Button1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs)
If FileUpload1.HasFile Then
Try
FileUpload1.SaveAs("C:\inetpub\wwwroot\Uploads\" & _
FileUpload1.FileName)
Span1.Text = "You have specified a file."
Span1.Text = "File name: " & _
FileUpload1.PostedFile.FileName & "<br>" & _
"File Size: " & _
FileUpload1.PostedFile.ContentLength & " kb<br>" & _
"Content type: " & _
FileUpload1.PostedFile.ContentType
Catch ex As Exception
Span1.Text = "ERROR: " & ex.Message.ToString()
End Try
Else
Span1.Text = "You have not specified a file."
End If
End Sub
End Class
請讓我知道如果我失去了一些東西。
您正在混合使用MVC和WebForms ... –