开发者

Using MVC3/Razor where would I put images that were specific to one view?

Using MVC3/Razor where would I put images that were specific to one view?

Using MVC3/Razor where would I put images that were specific to one view?

I had thought to put it in the /vie开发者_如何学Gows/home folder and then reference it with the following line inside /views/home/index.cshtml, but I'm not getting it to resolve.

<a href="@Url.Content("rawchart.PNG")" target="_blank" style="float:right;"><img src="@Url.Content("rawchart.PNG")" style="max-width: 128px; max-height: 64px;" title="click to view in a new window or tab" /></a> 

(so that you see my intent)

Is this a dumb way of doing this? Should I just have it in /content/images instead?


You could place them in:

~/Content/images/Home/Index/image1.png
~/Content/images/Home/Index/image2.png
~/Content/images/Home/Edit/image1.png
~/Content/images/Home/Edit/image2.png
...

and then:

<a href="@Url.Action("Foo")" target="_blank" style="float:right;">
    <img src="@Url.Content("~/content/images/home/index/image1.png")" style="max-width: 128px; max-height: 64px;" title="click to view in a new window or tab" />
</a>


You can't put them in the Views folder. No content can be there. There really isn't an 'mvc way'. Just use something like /content/images/viewname.


Put the images in your Content folder (or subfolder) and use a relative URL

@Url.Content("~/Content/myimage.png")


I think you should probably put the images with the other images in the Content folder. I would lay out your images folder (in Content) similarly to your Views folder if it makes it easier for your and future maintainers to manage. I do something similar with javascript in the Scripts folder.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜