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 ?
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':
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.
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.
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.
Yes, ineheriting RenderViewPage does not stop you from accessing Model or DynamicModel.
Unless I'm misreading this question.
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.
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.
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
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.
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.
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':
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.
I tried in the way you provided:
From the parent View:
From the child View:
Result on screen is
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...
Is that actually a bug ?!
is working on a reply...