C
C#3y ago
big OOF

Display base64 img on Razor page

Hello, Im trying to display a base 64 image on a razor page. Pagemodel:
public string imagedata { get; set; } = "";
public void OnPostGetSelectedImage()
{
string myBase64 = "examplebase64";

imagedata = string.Format($"data:image/png;base64", myBase64);
}

public string imagedata { get; set; } = "";
public void OnPostGetSelectedImage()
{
string myBase64 = "examplebase64";

imagedata = string.Format($"data:image/png;base64", myBase64);
}

Page:
<div class="container">
<div class="form-group">
<img id="UserImage" src="@Model.imagedata" alt="your image" />
</div>
<div class="container">
<div class="form-group">
<img id="UserImage" src="@Model.imagedata" alt="your image" />
</div>
The image is not showing and im woundering if this is the correct way of thinking or should i change it from void to something that reloads the page?
Thanks in advance! 🙂
6 Replies
Angius
Angius3y ago
string.Format($"data:image/png;base64", myBase64);
string.Format($"data:image/png;base64", myBase64);
this will do nothing
MODiX
MODiX3y ago
Angius#1586
REPL Result: Success
string myBase64 = "examplebase64";
var imagedata = string.Format($"data:image/png;base64", myBase64);
imagedata
string myBase64 = "examplebase64";
var imagedata = string.Format($"data:image/png;base64", myBase64);
imagedata
Result: string
data:image/png;base64
data:image/png;base64
Compile: 498.852ms | Execution: 27.613ms | React with ❌ to remove this embed.
Angius
Angius3y ago
As you can see You seem to be trying to use string interpolation and string format at once, but also failing to use either
MODiX
MODiX3y ago
Angius#1586
REPL Result: Success
var x = "hello";
var interpolation = $"Here's interpolation {x}!";
var format = string.Format("Here's string.Format {0}", x);

new { interpolation, format }
var x = "hello";
var interpolation = $"Here's interpolation {x}!";
var format = string.Format("Here's string.Format {0}", x);

new { interpolation, format }
Result: <>f__AnonymousType0#1<string, string>
{
"interpolation": "Here's interpolation hello!",
"format": "Here's string.Format hello"
}
{
"interpolation": "Here's interpolation hello!",
"format": "Here's string.Format hello"
}
Compile: 502.614ms | Execution: 68.779ms | React with ❌ to remove this embed.
Angius
Angius3y ago
Use one or the other (preferably interpolation) And, what matters the most, use them correctly
big OOF
big OOFOP3y ago
Okey ill try it out, thank you guys! 🙂
Want results from more Discord servers?
Add your server