ASP.NET MVC not displaying image

PeanutsMonkey

I have the code below however when i execute the page i get the error as follows

/Images/@Model.ImageID.jpeg

Error

CS1061: 'int' does not contain a definition for 'jpeg' and no extension method 'jpeg' accepting a first argument of type 'int' could be found (are you missing a using directive or an assembly reference?)

If i do /Images/@Model.ImageID%20.jpeg, there is no error but no image is displayed.

Viktor Bahtev

You can try:

/Images/@(Model.ImageID).jpeg

In your example the Razor View Engine thinks that you want to call property jpeg on Model.ImageID but ImageID is of type int and does not contain a definition for jpeg as the error says. When you add the parenthesis you tell to Razor to execute as expression only what is inside them and .jpeg became just a text after the Id. This is called Explicit expression.

You can find something useful here - Razor Syntax Quick Reference.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related