Copied to clipboard

Flag this post as spam?

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


  • TempleClause 32 posts 248 karma points
    Feb 18, 2015 @ 20:32
    TempleClause
    0

    Using @Html.EditorFor(x=>Model) in PartialView

    I am trying to Render a form for a model in a partial view. But I can't get it working. Here is my code of the TestForm.cshtml:

    @model NgakNgakBeach.Models.Reservation
    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @using (Html.BeginUmbracoForm("MakeReservation", "Reservation",
                                      new { enctype = "multipart/form-data" }, null,                                                                             FormMethod.Post))
    {
        @Html.EditorFor(x => Model)
        <input type="submit" />
    }
    

    What is the trick to get this working?

    Error message from VisualStudio 2013:

    The 'inherits' keyword is not allowed when a 'model' keyword is used.   
    

    Thanks!

    EDIT: in this tutorial https://our.umbraco.org/documentation/Reference/Mvc/forms/turorial-partial-views shouldn't the CommentViewModel inherit something?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Feb 18, 2015 @ 21:52
    Dennis Aaen
    0

    Hi TempleClause,

    What I can see from the documentation that you are posting https://our.umbraco.org/documentation/Reference/Mvc/forms/turorial-partial-views, then it just have this

    @model NgakNgakBeach.Models.Reservation

    And not both.

    @model NgakNgakBeach.Models.Reservation
    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

    Try also to see this post from Stackoverflow. http://stackoverflow.com/questions/21060767/the-inherits-keyword-is-not-allowed-when-a-model-keyword-is-used or if you should have both, then I think from this post http://stackoverflow.com/questions/8127462/the-view-must-derive-from-webviewpage-or-webviewpagetmodel/8127539#8127539 it should be

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @model
    NgakNgakBeach.Models.Reservation

    Hope this helps,

    /Dennis

  • TempleClause 32 posts 248 karma points
    Feb 18, 2015 @ 23:57
    TempleClause
    0

    Thanks for the answer, I now noticed that my problem is of a different nature. I try to call

    @{ Html.RenderPartial("TestForm"); }
    

    from a MacroPartial, but that doesn't seem to work. Is this not possible?

    Oh and this is not very helpful:

    Error loading Partial View script (file: ~/Views/MacroPartials/Reservation.cshtml)
    

    Is there a way to print out more accurate error messages?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 19, 2015 @ 00:01
    Jan Skovgaard
    0

    Hi TempleClause

    You should be able to see more details about the error by going to the /App_Data/Logs file.

    Hope this helps.

    /Jan

  • TempleClause 32 posts 248 karma points
    Feb 19, 2015 @ 21:00
    TempleClause
    0

    Is it not possible to render a PartialView from a MacroPartialView? I'm still getting an error....

    In my Reservation.cshtml I have:

    @{ Html.RenderPartial("TestForm"); }
    

    And in my TestForm.cshtml I have:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    <p>test</p>
    

    and I get this error in the log:

    Error loading Partial View (file: ~/Views/MacroPartials/Reservation.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 'Umbraco.Web.Models.RenderModel'.

    Thanks for helping

    EDIT:

    I don't have any problems calling this from a non MacroPartialView:

    @{ Html.RenderPartial("TestForm"); }
    
  • TempleClause 32 posts 248 karma points
    Feb 19, 2015 @ 21:08
    TempleClause
    100

    Got it working, see solution here: https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/53209-Render-PartialView-%28UmbracoTemplatePage%29-from-Macro-%28PartialViewMacroPage%29

    @{ Html.RenderPartial("TestForm", Model.Content); }
    

    Should use google first ... sorry guys

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies