我是 vb 编程的新手,一直在尝试实现一个上传表单来将文件上传到我的网络服务器。我正在使用 .vbhtml 和 VB 。我已经创建了表单,但是当我单击提交按钮 "Button1_Click" 时,什么也没有发生。这是我的代码
---- Index.vbhtml 代码 -----
@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>
-------- HomeController.vb中使用的代码--------
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
如果我遗漏了什么,请告诉我。