Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Pinal Bhatt 298 posts 389 karma points
    Dec 27, 2012 @ 13:16
    Pinal Bhatt
    0

    "Cannot perform runtime binding on a null reference" error from partial views

    Hi Community 

    I am getting following error while using Partial view with @Html.Partial()

    Code:

     

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using PBDesk.Website.Extension.UmbHelpers
    @using PBDesk.DataContract.UDocs
    @{
    eBook ebod = ContentHelper.GetEBOD();
    }
    <div class="span3">
        <h2>eBook Of The Day</h2>
        <div>@ebod.NiceUrl</div>
        <div>@CurrentPage.Id</div>
        <div class="image-wrapper custom-image-wrapper">
            <i class="icon-book"></i>
        </div>
        <p>@ebod.Title <a href="@ebod.NiceUrl"><img alt="@ebod.Title"  src="@ebod.ThumbnailUrl" /><br/><br/><button type="button" class="btn btn-danger">Get the eBooks ยป</button></a></p>
    </div>

     

    Error:

  • Pinal Bhatt 298 posts 389 karma points
    Dec 27, 2012 @ 13:22
    Pinal Bhatt
    0

    Here is the exact error message:

    Server Error in '/' Application.


    Cannot perform runtime binding on a null reference

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference

    Source Error: 

    Line 8:      <h2>eBook Of The Day</h2>
    Line 9:      <div>@ebod.NiceUrl</div>
    Line 10: <div>@CurrentPage.Id</div> Line 11:     <div class="image-wrapper custom-image-wrapper">
    Line 12:         <i class="icon-book"></i>


    Source File: c:\HostingSpaces\pbdesk\pbdesk.com\wwwroot\Views\Partials\HeroUnits\eBookOfTheDay.cshtml    Line: 10 

    Stack Trace: 

    [RuntimeBinderException: Cannot perform runtime binding on a null reference]
       CallSite.Target(Closure , CallSite , Object ) +115
       System.Dynamic.UpdateDelegates.UpdateAndExecute1(CallSite site, T0 arg0) +432
       ASP._Page_Views_Partials_HeroUnits_eBookOfTheDay_cshtml.Execute() in c:\HostingSpaces\pbdesk\pbdesk.com\wwwroot\Views\Partials\HeroUnits\eBookOfTheDay.cshtml:10
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +197
       System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +81
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +88
       System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +222
       System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +115
       System.Web.Mvc.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, TextWriter writer, ViewEngineCollection viewEngineCollection) +276
       System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData) +108
       System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName) +31
       ASP._Page_Views_Partials_HeroUnits_VerticalHeroList_cshtml.Execute() in c:\HostingSpaces\pbdesk\pbdesk.com\wwwroot\Views\Partials\HeroUnits\VerticalHeroList.cshtml:6
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +197
       System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +81
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +88
       System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +222
       System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +115
       System.Web.Mvc.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, TextWriter writer, ViewEngineCollection viewEngineCollection) +276
       System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData) +108
       System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, ViewDataDictionary viewData) +10
       ASP._Page_Views_EBooksItemPage_cshtml.<Execute>b__d() in c:\HostingSpaces\pbdesk\pbdesk.com\wwwroot\Views\eBooksItemPage.cshtml:30
       System.Web.WebPages.<>c__DisplayClassb.<RenderSection>b__9(TextWriter tw) +278
       System.Web.WebPages.HelperResult.WriteTo(TextWriter writer) +10
       System.Web.WebPages.WebPageBase.Write(HelperResult result) +71
       ASP._Page_Views__Layout93_cshtml.Execute() in c:\HostingSpaces\pbdesk\pbdesk.com\wwwroot\Views\_Layout93.cshtml:20
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +197
       System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +81
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +88
       System.Web.WebPages.<>c__DisplayClass7.<RenderPageCore>b__6(TextWriter writer) +102
       System.Web.WebPages.HelperResult.WriteTo(TextWriter writer) +10
       System.Web.WebPages.WebPageBase.Write(HelperResult result) +71
       System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body) +65
       System.Web.WebPages.WebPageBase.PopContext() +260
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +95
       System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +222
       System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +115
       System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +295
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
       System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +23
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +242
       System.Web.Mvc.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b() +21
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +177
       System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +324
       System.Web.Mvc.Controller.ExecuteCore() +106
       System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +91
       System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
       System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +34
       System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +19
       System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10
       System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
       System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +48
       System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
       System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
       System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
       System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9629708
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
    



    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929

  • Pinal Bhatt 298 posts 389 karma points
    Dec 30, 2012 @ 14:28
    Pinal Bhatt
    0

    hi community ...any help please on this.

  • Jan Skovgaard 11242 posts 23414 karma points MVP 6x admin c-trib
    Dec 30, 2012 @ 15:26
    Jan Skovgaard
    0

    Hi Pinal

    What version of Umbraco are you using?

    /Jan

  • Pinal Bhatt 298 posts 389 karma points
    Dec 30, 2012 @ 15:37
    Pinal Bhatt
    0

    its Umbraco 4.11.1

  • Jan Skovgaard 11242 posts 23414 karma points MVP 6x admin c-trib
    Dec 30, 2012 @ 15:47
    Jan Skovgaard
    0

    Hi Pinal

    I suspect it's because there is no @CurrentPage...I must admit that I'm not very fluent at Razor yet but I think you should do this...

    var currentPage = @Model;

    and then cal the currentPage variable like @currentPage.Id.

    Does this help?

    /Jan

  • Pinal Bhatt 298 posts 389 karma points
    Dec 30, 2012 @ 15:54
    Pinal Bhatt
    0

    I dont think @CurrentPage should be an issue because I am using it very often. Most like it was introduced in U4.11 (http://our.umbraco.org/documentation/reference/mvc/views)

    FYI - I am using MVC views and not umbraco macros.

    @Model does not works with MVC views.

  • Jan Skovgaard 11242 posts 23414 karma points MVP 6x admin c-trib
    Dec 30, 2012 @ 15:56
    Jan Skovgaard
    0

    Hi Pinal

    Yes, my bad - Having a hard time keeping up with all the nice new stuff we get to explore :) Just stumpled across Shannon's blogpost about it. My bad!

    I will try to wrap my head around it and see if I figure something out.

    /Jan

  • Jan Skovgaard 11242 posts 23414 karma points MVP 6x admin c-trib
    Dec 30, 2012 @ 16:17
    Jan Skovgaard
    0

    Hi Pinal

    I think I've been mistaken about the error. Seems to me you're missing () after the NiceUrl() on this line: @ebod.NiceUrl

    Try writing: @ebod.NiceUrl()

    Does this help? :)

    /Jan

  • Pinal Bhatt 298 posts 389 karma points
    Dec 30, 2012 @ 16:30
    Pinal Bhatt
    0

    Thanks Jan.

    Nopes ebod.NiceUrl is also not an issue. I am aware of NiceUrl() issue with 4.11.1.  

    Btw in above code "ebod" is an object of my custom class "eBook" and I have string property NiceUrl defined in that class.

     

  • Pinal Bhatt 298 posts 389 karma points
    Jan 04, 2013 @ 16:09
    Pinal Bhatt
    0

    Hi Community.. any help on this.....

  • sagar 13 posts 33 karma points
    Mar 13, 2014 @ 11:46
    sagar
    0

    hi all 

    i am trying to get page using id

    and in razor when i call  that  cshtml file it gives me error any help on this

    and without id i can do my stuff

Please Sign in or register to post replies

Write your reply to:

Draft