I have done this a long time ago in VB.NET, I removed redundant code and here how it should look like:
HTML part:
<form action="AddToDatabase" method="post" enctype="multipart/form-data">
<input type="id" name="pictureId"/> <br/>
<input type="file" name="picture" accept="image/gif, image/jpeg" required/> <br/>
<input type="submit" value="Upload" />
</form>
This takes the browsed image and passes to the AddToDatabase function inside Controller
Controller:
Public Class HomeController
Public Function AddToDatabase(ByVal pictureId as Long, ByVal picture As HttpPostedFileBase)
Dim manager As New DbWorks
Dim result = manager.SaveAndResize(pictureId, picture)
Return Content(result)
End Class
Controller takes pictureId and picture itself and passes it to DbWorks Service class, which does all the work
DbWorks Class:
Public Class DbWorks
Public Function SaveAndResize(ByVal picturetId As Long, ByVal picture As HttpPostedFileBase) As String
Dim picSource As Image = Image.FromStream(picture.InputStream)
Dim bmSource As New Bitmap(picSource)
Dim bmDest As New Bitmap(300, 300) //Saves in 300x300 resolution
Dim grDest As Graphics = Graphics.FromImage(bmDest)
grDest.DrawImage(bmSource, 0, 0, bmDest.Width, bmDest.Height)
Dim picDest As Image = bmDest
picDest.Save(HttpContext.Current.Server.MapPath("~/Pictures/" + CStr(pictureId) + ".jpeg"))
Dim path = ("~/Pictures/" + CStr(pictureId) + ".jpeg")
Return path
End Function
End Class
SaveAndResize function takes the image with id and transforms it into bitmap and saves in 300x300 resolution creating a path to your file in the system associated with a pictureId.
Don't forget to add System.Drawing library to manage with your image.
P.S. I am pretty sure you are doing your work in c#, but it won't take you much time to transform it. Also, in this case you can avoid using jquery library.