I am writing an asp.net core website, that shows a picture being generated elsewhere. And am polling the webapi on elsewhere, that I have written and named elseware ;-)
Basically I need to update the path to the image shown, when the image is avalible and uploaded to my websites server. I am polling from javascript, too see if the image is available, and when it is, I want to go to my pageModel of the RazorPage, and call a function on that, preferably passing the name of the image. The function should then call elseware for the image, and store it on the server, and returning it's local path.
Getting the C# function with the image name as parameter is somewhat troublesome.
.cs file:
public class xxModel:PageModel {
...
public string UploadImage(string imageName) {
var image = elseware.GetImage(imageName);
string newPath = saveImage(image);
return newPath;
}
}
.cshtml file:
var pollForImage = function (imageName) {
var imagePath = @Model.UploadImage(imageName); //<== this is where it
// fails.. I cannot get
// the call to work with
// a parameter..
$("#image").attr("src", imagePath);
}
I don't know if this a smart way to solve it, but I think it should be doable. If I make the ImagePath a public property on the class, I can overwrite the get and set operations of the property. But that would not be clear.
I don't want to use the OnPost/OnGet on the page. And please note that this is asp.net core mvc/web api v. 2.0 - (quite new at the moment)