jawad hasan
jawad hasan

Reputation: 115

Icons for each file type

In my MVC application, user can upload various type of files (pdf, jpg, txt etc) and I want to show icon specific to each type, currently I am using one icon (pdf) for the purpose, I want, that based on the file type, associated icon should be displayed. Please guide me what kind of approach I can use for this purpose

<td>
@if (item.CalibratedBy != null){
<a href = @Url.Action("ViewCertificate", new { fileName = item.CalibrationCert }) > 
<img src = "@Url.Content("~/Content/Icons/pdf.jpg")"  alt = "attachment" /> </a>
}
</td>

Upvotes: 0

Views: 1192

Answers (1)

Yaakov Ellis
Yaakov Ellis

Reputation: 41530

  1. Expose the extension type needed as a property on item (presumably being passed in through the Model)
  2. Create an HtmlHelper extension method that will take in item.FileType and return the path to the appropriate icon file to be used. Call this in your <img> tag.

Upvotes: 2

Related Questions