Get media Url in MVC project

John Ojuara asked on December 28, 2016 03:00

Hi,

I have two separate projects, one for K10 and an other for Mvc. I have followed the stepts to setup the projects as discribed here: https://docs.kentico.com/k10/developing-websites/developing-sites-using-asp-net-mvc/starting-with-mvc-development

In Document type I have a Media selection field. When I try to get that media Url I am getting a relative url instead of the absolute one: /MySite/media/Videos/test.mp4?ext=.mp4

I have tried by different ways like: @Url.Kentico().FileUrl(Model.Fields.Video, new FileUrlOptions(){AttachmentContentDisposition = false}), but I am still getting the relative path.

I saw some references about @Url.Kentico().Attachment() but Visual studio complains that Attachment does not exist.

I have installed the next packages: Kentico.Content.Web.Mvc Kentico.MediaLibrary Kentico.Web.Mvc

These are included in the Views Web.config

What am I doing wrong?

Thanks.

Correct Answer

Dragoljub Ilic answered on December 28, 2016 10:17

Hi John,

Why do you need to use absolute path? By default, content of media libraries is synchronized via web farms and duplicated between Kentico and your MVC application. In that case, you can use relative path without problems. Check this article.

If you need to store media files in one location, see this one article.

1 votesVote for this answer Unmark Correct answer

Recent Answers


Roman Hutnyk answered on December 28, 2016 10:18

Have you tried something like?:

@URLHelper.GetAbsoluteUrl(model.field)
2 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.