I need to transfer my download file to my controller using jquery ajax.
JS:
$('#btnpopupreg').click(function () { $.ajax({ type: 'POST', url: '/Membership/Register', data: $('#frmRegister').serializeArray(), dataType: 'json', headers: fnGetToken(), beforeSend: function (xhr) { }, success: function (data) {
View:
@model Test.RegisterViewModel @{ using Html.BeginForm(Nothing, Nothing, FormMethod.Post, New With {.id = "frmPopUpRegister", .enctype = "multipart/form-data"}) } <input type="file" /> //rest of my strongly typed model here <input type="button" value="BUTTON" /> //rest of the code here
Controller:
[HttpPost()] [AllowAnonymous()] [ValidateAntiForgeryToken()] public void Register(RegisterViewModel model) { if (Request.Files.Count > 0) {
I can get the model value just fine, but Request.Files always returns null. I also tried using HttpPostedFileBase, but it also always returns null
[HttpPost()] [AllowAnonymous()] [ValidateAntiForgeryToken()] public void Register(RegisterViewModel model, HttpPostedFileBase files) {
source share