I have a controller which return back a url of an image. The imageurl.AbsoluteUri is a file path, and is getting returned, lets says its returning “myserver.windows.net/myimagename”
(using fineUploader btw)
How do I get that value into my Model?
This is the jquery I am calling to call the fileUpload method in image controller
function createUploader() {
var uploader = new qq.FineUploader({
element: $('#fine-uploader')[0],
debug:true,
text: {
uploadButton: 'SELECT FILE'
},
request: {
endpoint: '@Url.Action("UploadFile", "Image", new { qqfile = "Image" })'
},
callbacks: {
onComplete: function(id, fileName, responseJSON) {
if (responseJSON.success == false && responseJSON.limitReached) {
$.confirm({
'@Model.Image':'imageurl'
});
} else {
addImage(responseJSON.idImage, responseJSON.imageType, responseJSON.showDescriptionOptions);
}
}
},
});
and here is what it returns it, which the imageurl is actually “myserver.windows.net/myimagename”
return Json(new { success = true, imageurl = imageurl.AbsoluteUri }, "text/html");
I figured it would be something to do with the onComplete section, but not sure how to actually pull the imageurl value
You can’t store client side javascript data in your MVC models. MVC models are executed on the server at the time of the request, and browsers have no idea how to interact with them.
You’ll need to deal with the response yourself, using jQuery to update the appropriate parts of the page. For example, if you want to update an image with the response:
Edit based on your comment:
You can just use jquery’s .text() to set the text of an element.
And then somewhere on the page: (the div’s are irrelevant, just added for SO formatting)