JavaScript readAsArrayBuffer to bytes and pass it to MVC controller

AzureDevUser 1 Reputation point

Hello all I have the following code where I have created a model to pass the documents. My model is as follows

public class Student
    public string StudentName {get;set;}
    public List<Document> Documents { get; set; }

public class Document 
  public string DocumnetName {get;set;}
   public byte[] DocumentData {get;set;}

public JsonResult PostUserData(Student StudentData)


Here is the fiddle I am trying out

A set of technologies in the .NET Framework for building web applications and XML web services.
3,411 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Bruce ( 61,266 Reputation points

    if your client code is converting to base64, then its passed as string, so you need a view model. once received on the server, it can convert the base64 string back to a buffer.

  2. Yijing Sun-MSFT 7,071 Reputation points

    Hi @AzureDevUser ,
    As far as I think,you could convert to base64 string using the javascript.And then you could use ajax to post the parameter to the controller.Just like this:
    Best regards,
    Yijing Sun

    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

  3. AgaveJoe 27,656 Reputation points

    File upload is a very straight forward in MVC using an HTML Form and the file input element. The browser handles file stream so there is little reason to convert the file to an array manually.

    ASP.NET MVC 5 with EF 6 - Working With Files

    If you are building a JavaScript solution then take advantage of the FormData object to upload a file.

    Using FormData Objects
    Using files from web applications

    If you still need assistance then share your code so the community can see how your are approaching this problem.