Copied to clipboard

Flag this post as spam?

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


  • Artem 1 post 21 karma points
    Apr 17, 2013 @ 16:00
    Artem
    0

    Partial View Macro with custom model

    Hi all.

    I had used this instruction for creating solution with umbraco 6.0.3: http://www.ben-morris.com/using-umbraco-6-to-create-an-asp-net-mvc-4-web-applicatio

    Then I have created Partial View Macro File (named MyView) using appropriate node in "Developer" menu in admin view.

    Then I have add MyView.cshtml to solution.

    If I understand correctly the view should contains @inherits Umbraco.Web.Macros.PartialViewMacroPage

    So, Is it a way to have cutom Model for view?

    I'm trying to do something like:

    @inherits UmbracoViewPage<SomeWebProject.Models.MyModel>

    @Model.SomeProprty

    But in this case I have the error:

    Error loading Partial View (file: ~/Views/MacroPartials/MyView.cshtml). Exception: System.InvalidOperationException: The model item passed into the dictionary is of type 'Umbraco.Web.Models.PartialViewMacroModel', but this dictionary requires a model item of type 'SomeWebProject.Models.MyModel'.
       at System.Web.Mvc.ViewDataDictionary`1.SetModel(Object value)
       at System.Web.Mvc.ViewDataDictionary..ctor(ViewDataDictionary dictionary)
       at System.Web.Mvc.WebViewPage`1.SetViewData(ViewDataDictionary viewData)
       at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
       at Umbraco.Web.Mvc.ControllerExtensions.RenderViewResultAsString(ControllerBase controller, ViewResultBase viewResult)
       at Umbraco.Web.Macros.PartialViewMacroEngine.Execute(MacroModel macro, INode currentPage)
       at umbraco.macro.LoadPartialViewMacro(MacroModel macro)
       at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)

     

    Thanks for any help

  • Barry Fogarty 493 posts 1129 karma points
    Apr 17, 2013 @ 16:28
    Barry Fogarty
    0

    Hi Artem

    You should only use a Partial View Macro for macros you want to be able to embed in the rich text editor, via the Embed Macro function.  Try creating it as a Partial View, if you only need to reference it in a template.  Then your inherit statement should work.

    Check this topic too:

    http://our.umbraco.org/forum/developers/api-questions/40032-MVC-Using-the-UmbracoHelper-dictionary-in-a-Partial-View-with-a-custom-model

Please Sign in or register to post replies

Write your reply to:

Draft