I am facing an issue while fetching the media item URL. This is my code snippet:
@{
Sitecore.Data.Fields.ImageField imageItem = (Sitecore.Data.Fields.ImageField)Sitecore.Context.Item.Fields["BackgroundImage"];
var titleUrl = Sitecore.Resources.Media.HashingUtils.ProtectAssetUrl(
Sitecore.Resources.Media.MediaManager.GetMediaUrl(
imageItem.MediaItem,
new MediaUrlOptions()
{
Language = Sitecore.Context.Language,
Height = 600
}));
}
I am using this titleUrl
in the image tag:
<img src="@titleUrl" />
But while fetching the URL, MediaManager is throwing this error:
System.ArgumentNullException
HResult=0x80004003
Message=Value cannot be null.
Arg_ParamName_Name
Source=Sitecore.Kernel
StackTrace:
at Sitecore.Diagnostics.Assert.ArgumentNotNull(Object argument, String argumentName)
at Sitecore.Resources.Media.MediaProvider.GetMediaUrl(MediaItem item, MediaUrlOptions options)
at ASP._Page_Views_DeepContent_PageHeader_Index_cshtml.Execute() in c:\inetpub\wwwroot\sitecoretac\Views\Index.cshtml:line 13
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
What is the issue here? Thanks for the help.