I am trying to do upload attachment functionality using MVC. My method that is actually doing the upload/save attachment is expecting a HttpPostedFileBase type.
public virtual string Upload(HttpPostedFileBase fileName)
{
//Code to upload/save attachment.
}
My problem is "fileName" is being passed from the UI as a string. How can I convert the string(file path name) into something my Upload method can work with.
Thanks in advance.
As mentioned by others, your form should look something like this:
<form id="form_UploadFile" action="" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
</form>
Then as you mentioned you are trying to post via ajax, you can use jQuery serialize() to serialize the formData to be pushed to your controller.
$('#form_UploadFile').serialize();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With