How to get an image from a vbhtml view

0

Dear, how can I get an image from a vbhtml view in this format:

@Html.LabelFor(Function(m) m.FchNacimientoPER)                
@Html.TextBoxFor(Function(m) m.FchNacimientoPER, new With {.class="form-control"})

I want to get the image as an array of bytes , can I get it as a byte() from the view? or I have to send it to the controller and then pass it to byte() to work it.

    
asked by ASP.NEET 25.11.2016 в 20:32
source

1 answer

0

You can do something like this:

@using (Html.BeginForm("Add", "Archivos",
                 FormMethod.Post, new { id = "attachment", enctype = "multipart/form-data", encoding = "multipart/form-data" }))
{ 

    <input type="file" name="uploadFile" id="uploadFile" />

   <input type="submit" value="Guardar"/>

}

On the controller:

<HttpPost> _
Public Function Add(uploadFile As HttpPostedFileBase) As ActionResult
If uploadFile IsNot Nothing AndAlso uploadFile.ContentLength > 0 Then

    Dim tempFile As Byte() = New Byte(uploadFile.ContentLength - 1) {}
    uploadFile.InputStream.Read(tempFile, 0, uploadFile.ContentLength)

    User1.file.Content = tempFile

    User1.file.Save()
End If

Return RedirectToAction("Index")

End Function

where User1.file.Content is of type byte[]

    
answered by 25.11.2016 в 21:03