Copied to clipboard

Flag this post as spam?

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


  • nicolas ruiz 74 posts 95 karma points
    Mar 27, 2012 @ 11:06
    nicolas ruiz
    0

    U5 PartialViews: @model vs @inherits RenderViewPage

    Hi there,

    I installed uBootstrap which includes a Contact Form set of PartialView, SurfaceController and Model.

    Problem is it's not following the (I asume it is) U5 standards to use a "@inherits RenderViewPage" on top of PartialView files. It uses instaed a @model to gain access to its ... model.

    Here is my problem, I'm sad to have to make a choice, model or Umbraco helpers... Isn't there a way to have both at the same time ?

    Thanks,

    Nicolas.

  • Grant Thomas 291 posts 324 karma points
    Mar 27, 2012 @ 11:46
    Grant Thomas
    0

    Yes, ineheriting RenderViewPage does not stop you from accessing Model or DynamicModel.

    Unless I'm misreading this question.

  • nicolas ruiz 74 posts 95 karma points
    Mar 27, 2012 @ 12:11
    nicolas ruiz
    0

    But @inherits and @model can not be called on the same PartialView.

    I then don't know how to manually call the inheritance or my model.

    That's the problem.

  • Grant Thomas 291 posts 324 karma points
    Mar 27, 2012 @ 12:37
    Grant Thomas
    0

    Maybe I'm confused, do you have an example? And also please state exactly which version you're using.

    I've been able to use Partials in U5 that come by default with the inheritance specifier and proceeded to access the Model directly.

  • nicolas ruiz 74 posts 95 karma points
    Mar 27, 2012 @ 12:55
    nicolas ruiz
    0

    Certainly, I'm using v5.0.1

    Generic out-of-the-box partial:

    @using Umbraco.Cms.Web
    @inherits RenderViewPage
    @{
            . . . .
            @Umbraco.GetDictionaryItem("/dict/key")
            . . . .
    }

    uBootstrap contact form partial:

    @using Umbraco.Cms.Web
    @using myProject.Models
    @model myModel
    {
            . . . .
            @Html.TextBoxFor(x => x.Name)
            . . . .
    }

    First example is good to have direct access to UmbracoHelper.
    Second example is good to have direct access to my custom model properties.

    One answer could come from here: http://weblogs.asp.net/scottgu/archive/2010/10/19/asp-net-mvc-3-new-model-directive-support-in-razor.aspx

  • nicolas ruiz 74 posts 95 karma points
    Mar 27, 2012 @ 14:01
    nicolas ruiz
    0

    Link above asks us to modify Views\Web.config

    As a result, my compiler run fine but Partial Views don't show up.

    Error thrown: error CS0308 - The non-generic type 'Umbraco.Cms.Web.RenderViewPage' cannot be used with type arguments.

  • nicolas ruiz 74 posts 95 karma points
    Mar 27, 2012 @ 15:15
    nicolas ruiz
    0

    Grant, when saying " and proceeded to access the Model directly.", could you show me a portion of code ?

    Also, where (or how) did this model, you're talking about, be defined ?

    Thanks,

    Nicolas.

  • Grant Thomas 291 posts 324 karma points
    Mar 27, 2012 @ 15:25
    Grant Thomas
    0

    Nicolas,

    My further queries were indeed something to do with my ignorance: I'd not seen the model defined as a distinct section in MVC before (yes, I'm new to this and that in the real world).

    But basically, forget about editing the web.config or anything and just go with a standard macro as defined by Umbraco upon creation. Now, we can access the model directly via 'Model':

    @using Umbraco.Cms.Web
    @inherits RenderViewPage
    @{
        . . . .
        @Model.Property
        . . . .
    }

    Of course this is now the default model that will be defined by Umbraco (I have no part in it, it's just the page from which the macro is being called) and if we wish to specify the model to be that of a custom entity, then from my understanding (or at least one way of doing it) would be to pass your model as an argument to the Html.Partial:

    @Html.Partial("myView", model)

    Now with my little experience I could possibly be missing a vital point of your request, but hopefully this helps.

  • nicolas ruiz 74 posts 95 karma points
    Mar 27, 2012 @ 17:29
    nicolas ruiz
    0

    I tried in the way you provided:

    From the parent View:

    @using Umbraco.Cms.Web
    @using myProject.Models
    @inherits RenderViewPage
    @{
       
    ....

       
    @Html.Partial("myPartialView", new myModel())
        ....
    }

    From the child View:

    @using Umbraco.Cms.Web
    @inherits RenderViewPage
    @{
       
    ....

       
    @Html.TextBoxFor(x => x.myProperty)
        ....
    }

    Result on screen is

    error CS1061: 'Umbraco.Cms.Web.Model.Content' does not contain a definition for 'myProperty' and no extension method 'myProperty' accepting a first argument of type 'Umbraco.Cms.Web.Model.Content' could be found (are you missing a using directive or an assembly reference?)

    It's like the second argument of Html.Partial is not used...It should use myProject.Models.myModel as Model and not Umbraco.Cms.Web.Model.Content in the child Partial View.

    Still digging...

  • nicolas ruiz 74 posts 95 karma points
    Mar 27, 2012 @ 18:28
    nicolas ruiz
    0

    Is that actually a bug ?!

Please Sign in or register to post replies

Write your reply to:

Draft