昨天我发布了一个问题,说明为什么我无法显示我的图片。 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中,我使用了Media Picker作为通用属性。别名是deal1image。它们位于名为Deals的标签下。
希望你们中的一个能帮助我。这是整个错误:
以下方法或属性之间的调用不明确:'Umbraco.Web.UmbracoHelper.Media(params int [])'和'Umbraco.Web.UmbracoHelper.Media(params string [])'
描述:执行当前Web请求期间发生了未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
异常详细信息: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
答案 0 :(得分:2)
更新回答:
错误告诉您它不知道使用哪种方法,因为“deal1image”不返回任何内容。所以你必须检查“deal1image”是否有任何价值。像这样:
@if(CurrentPage.HasValue("deal1image"))
{
<img src="@Umbraco.Media(CurrentPage.deal1image).Url" />
}
您是否1000%确定“deal1image”是您的媒体资源的别名,并且您选择了umbraco中的任何媒体项目?