Navid_pdp11
Navid_pdp11

Reputation: 4012

how to pass model to partialview in umbraco?

I want to pass a object as model to a partial view in umbraco. there is two function @Html.Partial() and @Html.Partial() which have 4 override method listed below :

@Html.Partial(string partialName)
@Html.Partial(string partialName, Object object)
@Html.Partial(string partialName, Object object, ViewDataDictionary dic)
@Html.Partial(string partialName, ViewDataDictionary dic)

and :

@Html.RenderPartial(string partialName)
@Html.RenderPartial(string partialName, Object object)
@Html.RenderPartial(string partialName, Object object, ViewDataDictionary dic)
@Html.RenderPartial(string partialName, ViewDataDictionary dic)

I try to use @Html.RenderPartial(string partialName, Object object) and @Html.Partial(string partialName, Object object) but i an getting this Exception:

Cannot bind source type <>f__AnonymousType0`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] to model type Umbraco.Web.Models.RenderModel.

I search a lot in google to an example of using these methods but i cannot find any thing. so there are two question:

  1. What is different between Partial and RenderPartial method?
  2. How can I pass data to partialview from page razor?

Upvotes: 1

Views: 3039

Answers (1)

Navid_pdp11
Navid_pdp11

Reputation: 4012

I found solution. my PartialView was inherited from :

Umbraco.Web.Mvc.UmbracoTemplatePage

now i change its inheritance to :

@inherits Umbraco.Web.Mvc.UmbracoViewPage<MyModel>

and then I can add mymodel object to RenderPartial() Method.

Upvotes: 2

Related Questions