Home

Embedded Resources

Vici MVC has built-in support for serving embedded resources to the browser.

If you have an embedded resource in your application, you can generate a URL for it by calling the following method:

ResourceHelper.CreateResourceUrl(assembly, resourceKey, contentType);

  • assembly: a reference to the assembly where the embedded resource is defined (to get the current assembly, use Assembly.GetExecutingAssembly())
  • resourceKey: the name of the embedded resource. This usually is "Namespace.Path.FileName.Extension".
  • contentType: the MIME content type (for example: "text/javascript" or "image/jpeg")

To use the generated HTML, add it to the ViewData[] collection:

ViewData["ResourceURL"] = ResourceHelper.CreateResourceUrl(assembly, resourceKey, contentType);

And in your template:

<img src="{{ResourceURL}}" />