我是asp.net mvc的新手,但我正在尝试使用GDI+制作一个有趣的应用程序,并且需要在asp.net mvc中进行一些图像查看。
我有一个模型,其中包含一个图像属性:
namespace DomainModel.Entities
{
public class BackgroundImage
{
// Properties
public Image Image {get; private set; }
public BackgroundImage()
{
Image = Image.FromFile(@"D:\ProjectZero\DomainModel\image\bkg.PNG");
}
}
}
控制器向视图发送以下内容:
public ActionResult Index()
{
BackgroundImage bkImg = new BackgroundImage();
return View(bkImg);
}
视图如下所示:
<p> Height: </p><%= Model.Image.Height //it prints the height of the image %> </br>
<p> Width: </p><%= Model.Image.Width //it prints the width %> </br>
<p> Image: </p><%= Model.Image //does not work to display the image %>
如何显示图片属性?
我需要将背景图片用于一个div。我不需要调整图片大小,只需要以其正常尺寸显示。
是否有我所缺少的Html助手?
谢谢您的时间!
@
符号的概念。在WebForms视图引擎中,您需要使用<%
和%>
来呈现服务器端代码。 - Darin Dimitrov