如何在asp.net mvc上传视频

时间:2009-09-16 08:48:40

标签: asp.net-mvc

如何使用asp.net mvc在我的mysql数据库中上传视频?

视图:

<form method="post" enctype="multipart/form-data" action="<%=url.action("VideosInsert") %>">
<%Using Html.BeginForm%>
<p>
<label for="videourl">Browse url :</label>
<input type="file" name="video" />
</p>
<p>
<label for="caption">Caption :</label>
<%=Html.TextBox("caption", String.Empty, New With {Key .size = 100})%>
</p>
<p>
<label for="eventDate">Date of Event:</label>
<%=Html.TextBox("eventDate")%>
</p>
<p>
<label for="category">Category :</label>
<%=Html.TextBox("category")%>
</p>
<p>
<%=Html.CheckBox("feature")%>
<label for="feature">Feature</label>
</p>
<input type="submit" name="uploadvideo" value="Upload Video" />
<%End Using%>
</form>

控制器:

Imports System.IO

Public Class AdministrationController
    Inherits Global.System.Web.Mvc.Controller
    Private dVideos As New ClassVideosConnection

   <AcceptVerbs(HttpVerbs.Post)> _
    Function VideosInsert(ByVal video As HttpPostedFileBase, ByVal caption As String, ByVal eventDate As String, ByVal category As Integer, ByVal feature As Boolean) As ActionResult

        //the code goes here, i think

        dVideos.videoInsert(url:=video.FileName, caption:=caption, eventDate:=eventDate, IDcat:=category, featured:=dfeature)
        Return View()
    End Function
    End Class

型号:

Imports Microsoft.VisualBasic
Imports System.Data

Public Class ClassVideosConnection
Inherits ClassConnection

    Public Sub videoInsert(ByVal url As String, ByVal caption As String, ByVal eventDate As Date, ByVal IDcat As Integer, ByVal featured As Integer)
        Dim insert As String = String.Format("INSERT INTO videos(vidURL, vidCaption, vidEvent, IDcategory, vidFeatured) VALUES  ('{0}','{1}','{2}','{3}','{4}')", url, caption, eventDate, IDcat, featured)
        UpdateData(insert)
    End Sub
 End Class

我不知道这是否正确,但这是我在上传图片时使用的语法。 提前谢谢你!

1 个答案:

答案 0 :(得分:1)

您的代码的问题在于您打开表单两次(使用表单标记,然后使用Html.BeginForm调用。

您需要通过类似

的调用将enctype =“multipart / form-data”传递给html属性
Html.BeginForm(action,controller, FormMethod.Post, new { enctype="multipart/form-data"})

虽然我不确定VB的确切语法