不会显示图像,而是在我的母版页布局上给出错误。 Umbraco 7,剃须刀

Wont show image instead it gives error on my masterpage layout. Umbraco7, razor

昨天我发布了一个关于为什么我的图片无法显示的问题。 Cant get the image to show in Umbraco7 with razor

我得到了很好的正确答案。

问题是当我使用那些如何显示图像的示例时,我得到了这样的错误:

Line 1:  @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
Line 2:  @{
Line 3:      Layout = "Master.cshtml";
Line 4:  }
Line 5:  <div class="container">

如果我删除这个:

 <img src="@Umbraco.Media(CurrentPage.deal1image).Url" />

然后一切正常,只是没有任何图像。

在我名为 Home 的文档类型中,我将媒体选择器用作通用 属性。别名是 deal1image。它们位于 Deals 标签下。

希望你们中的一位能帮助我。

这是整个错误:

以下方法或属性之间的调用不明确:'Umbraco.Web.UmbracoHelper.Media(params int[])' 和 'Umbraco.Web.UmbracoHelper.Media(params string[])'

问题描述:当前网络请求执行过程中出现未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。

异常详细信息:Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:以下方法或属性之间的调用不明确:'Umbraco.Web.UmbracoHelper.Media(params int[])' 和 'Umbraco.Web.UmbracoHelper.Media(params string[])'

Line 1:  @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
Line 2:  @{
Line 3:      Layout = "Master.cshtml";
Line 4:  }
Line 5:  <div class="container">

堆栈跟踪:

[RuntimeBinderException: The call is ambiguous between the following methods or properties: 'Umbraco.Web.UmbracoHelper.Media(params int[])' and 'Umbraco.Web.UmbracoHelper.Media(params string[])']
   CallSite.Target(Closure , CallSite , UmbracoHelper , Object ) +226
   System.Dynamic.UpdateDelegates.UpdateAndExecute2(CallSite site, T0 arg0, T1 arg1) +686
   ASP._Page_Views_Home_cshtml.Execute() in c:\Users\Bo\Google Drev\ASPNET\SvaleredenCamping\SvaleredenCamping\Views\Home.cshtml:3
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +197
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +96
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +76
   System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +257
   System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +115
   Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer) +151
   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +294
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
   System.Web.Mvc.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17() +23
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +242
   System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +21
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +242
   System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +21
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +175
   System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +89
   System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +102
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +43
   System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +14
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +57
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +47
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
   System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +25
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +47
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9651188
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

更新的答案:

错误告诉您它不知道使用哪种方法,因为 "deal1image" 没有 return 任何东西。所以你必须检查 "deal1image" 是否有任何价值。像这样:

@if(CurrentPage.HasValue("deal1image"))
{
   <img src="@Umbraco.Media(CurrentPage.deal1image).Url" />
}

您是否 1000% 确定 "deal1image" 是您的 属性 的别名,并且您在 umbraco 中选择了任何媒体项目?