asp.net mvc - "Cannot Resolve Partial View X" in Umbraco 6 Html.Partial -
i'm using umbraco 6, , using new mvc architecture. have document type view template, has view model, instantiated , has it's properties populated controller. 1 of these properties collection, , in view template iterate through collection , render out partial view separate view model, using 'html.partial("partialname", modelobject)'
the weird problem i'm having firstly, in visual studio resharper warning telling me cannot resolve partial view name (i have checked 50 times , i've spelt correctly). additionally when navigate page, trusty ol' "object reference not set instance of object" ysod.
i have debugged code, , controller action hit fine, logic instantiate view model document type template works fine, , populates properties correctly, i've made sure properties still set inside view , loop rendering out collection items correctly instantiates view model object per collection item , sets properties correctly. breaks when hits html.partial.
document type view code below:
@foreach (keyvaluepair<decimal, ipublishedcontent> result in model.results) { propertysearchresultviewmodel model = objectmapper.searchresulttoviewmodel(result); html.renderpartial("propertysearchresultdesktop", model); }
partial view code below:
@using production.umbraco.extensions.models.viewmodels; @inherits umbracoviewpage<propertysearchresultviewmodel> <article id="property-result-@model.node.id.tolower()"> <p>@model.node.name</article> <p>distance: @model.distance miles</p> </article>
here screenshot of vs solution tree:
the 'newhomes.cshtml' document type view template returned newhomescontroller , view calling 'propertysearchresultdesktop.cshtml' partial view, created umbraco office, , placed automatically.
the umbraco website says can , should place partial views here
http://our.umbraco.org/documentation/reference/mvc/partial-views
but no matter try do, wont render partial. i've seen 1 other question on answer place in macropartials instead, dont want part of benefit of using partial views in umbraco 6 inherit umbracoviewpage typed model declaration, macropartials don't.
has encountered before?
fixed. issue model passing document type view controller.
in umbraco documentation says, can create controller hijack umbraco route , serve own view custom model, so:
public actionresult index(rendermodel model) { searchresultsviewmodel viewmodel = new searchresultsviewmodel return currenttemplate(viewmodel); }
and in view had:
@inherits umbracoviewpage<searchresultsviewmodel>
however, seems though, in order that, must make sure custom view model in inherits rendermodel constructor takes rendermodel parameter , sets properties on base object, so:
public class searchresultsviewmodel :rendermodel { public searchresultsviewmodel(rendermodel model) : base(model.content, model.currentculture) { } }
previously, view model had not inherited , had parameterless constructor.
this article led me right answer.
http://www.ben-morris.com/using-umbraco-6-to-create-an-asp-net-mvc-4-web-applicatio
also, side note, still resharper warning of "cannot resolve partial view propertysearchresultdesktop" think that's resharper bug rather error.
even full path , file extension in call, still complains.
i find odd though while debugging, old controller code, no exception thrown @ model binding stage or inside controller, or in view until go html.partial call.
anyway, hope helps having same issue.
Comments
Post a Comment