Copied to clipboard

Flag this post as spam?

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


  • Greg 25 posts 103 karma points
    May 05, 2016 @ 20:53
    Greg
    0

    I'm using Umbraco 7.4 with ModelsBuilder.

    I'm working within visual studio.

    I'm loving the new models builder to work with razor, however I'm having 1 issue. Html.RenderPartial doesn't seem to exist with modelbuilder I'm getting errors such as :

    Error   73  'System.Web.Mvc.HtmlHelper<Umbraco.Web.Models.RenderModel<Umbraco.Web.PublishedContentModels.LandingPage>>' does not contain a definition for 'RenderPartial' and no extension method 'RenderPartial' accepting a first argument of type 'System.Web.Mvc.HtmlHelper<Umbraco.Web.Models.RenderModel<Umbraco.Web.PublishedContentModels.LandingPage>>' could be found (are you missing a using directive or an assembly reference?)   
    

    Any ideas?

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    May 06, 2016 @ 06:58
    Dennis Adolfi
    0

    Hi Greg.

    Adding @using System.Web.Mvc.Html at the top of your view should solve this.

  • Greg 25 posts 103 karma points
    May 06, 2016 @ 12:40
    Greg
    0
    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.BranchLocationPage>
    @using ContentModels = Umbraco.Web.PublishedContentModels;
    @{
        Layout = "~/Views/Shared/_Layout.cshtml";
        var landingName = CurrentPage.AncestorOrSelf(2).Name;
    }
    
    <aside class="top-image">
        <img src="@Umbraco.Media(Umbraco.Field("headerImage", recursive: true).ToString()).Url">
        <h1 class="landing-name">@landingName</h1>
    </aside>
    
    <div class="content">
        <div class="two-column">
            <div class="column1 navigation">
                @{Html.RenderPartial("SideNavigation");}
            </div>
            <div class="column2">
                @{Html.RenderPartial("Breadcrumbs");}            
                <h1>@(Model.Content.ContentTitle != "" ? Model.Content.ContentTitle : Model.Content.Name)</h1>
                @{Html.RenderPartial("SocialLinks");}
                @Model.Content.Main
            </div>
        </div>
    </div>
    

    Here's a view which gets these errors:

    Error   8   'System.Web.Mvc.HtmlHelper<Umbraco.Web.Models.RenderModel<Umbraco.Web.PublishedContentModels.BranchLocationPage>>' does not contain a definition for 'RenderPartial' and no extension method 'RenderPartial' accepting a first argument of type 'System.Web.Mvc.HtmlHelper<Umbraco.Web.Models.RenderModel<Umbraco.Web.PublishedContentModels.BranchLocationPage>>' could be found (are you missing a using directive or an assembly reference?)
    Error   9   'System.Web.Mvc.HtmlHelper<Umbraco.Web.Models.RenderModel<Umbraco.Web.PublishedContentModels.BranchLocationPage>>' does not contain a definition for 'RenderPartial' and no extension method 'RenderPartial' accepting a first argument of type 'System.Web.Mvc.HtmlHelper<Umbraco.Web.Models.RenderModel<Umbraco.Web.PublishedContentModels.BranchLocationPage>>' could be found (are you missing a using directive or an assembly reference?)
    Error   10  'System.Web.Mvc.HtmlHelper<Umbraco.Web.Models.RenderModel<Umbraco.Web.PublishedContentModels.BranchLocationPage>>' does not contain a definition for 'RenderPartial' and no extension method 'RenderPartial' accepting a first argument of type 'System.Web.Mvc.HtmlHelper<Umbraco.Web.Models.RenderModel<Umbraco.Web.PublishedContentModels.BranchLocationPage>>' could be found (are you missing a using directive or an assembly reference?)
    

    Keep in mind I forgot to mention this in the first post. The page still renders fine. I simply get these errors in Visual Studio.

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    May 06, 2016 @ 12:43
    Dennis Adolfi
    0

    Did you try adding @using System.Web.Mvc.Html?

  • Greg 25 posts 103 karma points
    May 06, 2016 @ 12:46
    Greg
    1

    ... well that's embarrasing.

    However, shouldn't that be a default? I can't recall any other MVC project where I had to specify this in every view.

    EDIT: To clarify, I looked into the web.config in the views folder and this was intended present:

    <system.web.webPages.razor>
      <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      <pages pageBaseType="System.Web.Mvc.WebViewPage">
        <namespaces>
          <add namespace="System.Web.Mvc" />
          <add namespace="System.Web.Mvc.Ajax" />
          <add namespace="System.Web.Mvc.Html" />
          <add namespace="System.Web.Routing" />
          <add namespace="Umbraco.Web" />
          <add namespace="Umbraco.Core" />
          <add namespace="Umbraco.Core.Models" />
          <add namespace="Umbraco.Web.Mvc" />
          <add namespace="umbraco" />
          <add namespace="Examine" />
          <add namespace="Umbraco.Web.PublishedContentModels" />
        </namespaces>
      </pages>
    </system.web.webPages.razor>
    
  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    May 06, 2016 @ 12:54
    Dennis Adolfi
    0

    :) Yes, it should be a default, something must have gone missing during your installation. So if you dont want to add this using statement in every view, do this:

    Check your views Web.config (NOTE: the web.config in your Views folder, not the root web.config.). This file holds the defaults for every view in your solution. Check the element system.web.webPages.razor and namespaces, does it have a reference to System.Web.Mvc? It should, otherwise add it. Here are the namespaces from a clean install:

    <system.web.webPages.razor>
        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <pages pageBaseType="System.Web.Mvc.WebViewPage">
          <namespaces>
            <add namespace="System.Web.Mvc" />
            <add namespace="System.Web.Mvc.Ajax" />
            <add namespace="System.Web.Mvc.Html" />
            <add namespace="System.Web.Routing" />
            <add namespace="Umbraco.Web" />
            <add namespace="Umbraco.Core" />
            <add namespace="Umbraco.Core.Models" />
            <add namespace="Umbraco.Web.Mvc" />
            <add namespace="umbraco" />
            <add namespace="Examine" />
    

    With this configuration, you dont have to add the using statement in every view.

    Let me know if it works out for you!!

    Best of luck!!

  • Greg 25 posts 103 karma points
    May 06, 2016 @ 12:55
    Greg
    0

    Hahaha, we posted the same thing at the same time.

    As my edit says, it's already there, which is why I find this odd.

    EDIT: Actually... this brings up another question I have. I recently came back to Umbraco after a small hiatus (pre 7.2.4). I'm noticing that your version of MVC is 5 and not 4. Is the standard no longer to start a MVC 4 project and install umbraco through nuget?

  • Nik 1599 posts 7179 karma points MVP 6x c-trib
    May 06, 2016 @ 13:02
    Nik
    0

    Hi Greg,

    I think (I cannot confirm as my experience with 7.4 and Model builder is limited so far), that it is the dynamic creation of the models that causes that "error" in visual studio.

    I found that if I change my Model Builder configuration (I can't remember the exact details I'm afraid) so that when I build it built a DLL rather than the run time models that I believe are turned on by default, it made the errors go away.

    I think this is why it all works when it's running but not in Visual Studio.

  • Greg 25 posts 103 karma points
    May 06, 2016 @ 13:07
    Greg
    0

    Hi Nik,

    I'm actually already in DLL mode. I found this was the best way to work with it in Visual Studio.

    I'm starting to think this is might be a MVC4 <-> MVC5, perhaps I installed Umbraco incorrectly from the start and I'm getting unexpected errors.

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    May 06, 2016 @ 13:09
    Dennis Adolfi
    0

    Yes, Umbraco now runs on MVC5, so if you installed it on top of a MVC4 application, i can guess it would be a problem. Try to just change your views web.config to reference MVC5 instead.

  • Greg 25 posts 103 karma points
    May 06, 2016 @ 13:12
    Greg
    1

    Switching to 5.2.3 in the web.config.

    However, since it's not breaking the site, only giving me errors in VS that I can ignore, I'm gonna put this in the learning experience bug and move on.

    Thanks for the help.

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    May 06, 2016 @ 13:10
    Dennis Adolfi
    0

    When installing Umbraco, i usally just create a Empty ASP.NET Web Application, and then install Umbraco with nuget. Umbraco ships with everything it needs in terms om MVC and what not.

    Best of luck!

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    May 06, 2016 @ 13:14
    Dennis Adolfi
    0

    Sounds like a great idea Greg!

    Good luck with the rest of your site!! :)

    Have a great day!!!

Please Sign in or register to post replies

Write your reply to:

Draft