以下是一个使用ASP.NET Core显示图像设置为属性的示例代码:
public class ImageModel
{
public string ImageUrl { get; set; }
}
public IActionResult DisplayImage()
{
var model = new ImageModel
{
ImageUrl = "https://example.com/image.jpg" // 设置图像的URL
};
return View(model);
}
@model ImageModel
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// ...
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
// ...
}
现在,当你访问/displayimage URL时,将显示指定URL的图像。你可以根据需要更改ImageModel类中的属性以存储和显示其他图像URL。