I have an account page where a user can update his/her profile picture. I use Amazon S3 to store the images so after a successful upload, I return the image URL to populate the image src and a TextBoxFor with a value of the URL. However, when I submit my form, the model that is submitted to my POST still contains the desktop filename instead of the Amazon S3 URL.
Here's my ajax call that (upon success) populates an img field and a TextBoxFor field:
$.ajax
({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/Account/UploadProfImageToS3Return",
data: formdata,
processData: false,
contentType: false,
success: function (data) {
$("#profile-image").attr("src", data);
$("#profImage").attr("value", data);
},
error: function (jqXHR, textStatus, errorThrown) {
//TODO: Indicate Error
console.log(jqXHR);
}
});
});
Here is my Html.BeginForm:
@using (Html.BeginForm("General", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
<img id="profile-image" src="@Model.Artist.ImageURL" alt="Profile Image" />
@Html.TextBoxFor(m => m.Artist.ImageURL, new { @name = "profImage", @id = "profImage", @type = "file" })
<div class="form-group">
<input type="submit" value="Save" class="btn btn-default btn-form" />
</div>
}
The file, when added to the @Html.TextBoxFor(m => m.Artist.ImageURL, new { @name = "profImage", @id = "profImage", @type = "file" })
is called: 20507471_10214.jpg and after the file is uploaded the value of that TextboxFor is now https://s3.amazonaws.com/unlink/profile-picture/xxxxxxx.jpg (because I update the field after AJAX success)
But when I set a breakpoint on my POST here:
[HttpPost]
public ActionResult General(Artist artist)
and I inspect the artist.ImageURL it still equals 20507471_10214.jpg
What can I do to fix this?
EDIT, image to prove that the value/src attribute of each is being set properly:

@name = "profImage"- fortunately that does nothing at all (and if it did work, then model binding would fail)[Bind(Prefix="Artist")]attribute). In any case you should never use data models in view when editing data - always use a view model