Copied to clipboard

Flag this post as spam?

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


  • Tom Bruce 122 posts 506 karma points
    Nov 30, 2018 @ 00:42
    Tom Bruce
    0

    SOS - Return partial view renders without master page layout!!!

    Hi everyone, I’m trying to return a partial view with its master template, but the partial view is being rendered with no master template.

    I have a page with a link, if the user clicks on the link, the link will fire the method within the controller

    <a href="@Url.Action("RenderEditRecord", "Record", new { RecordId = d.RecordID })" >Edit</a>
    

    Controller

    public ActionResult RenderEditRecord(ApplicationViewModel model, int RecordID)
        {
    
    
            return PartialView(GetViewPath1("_adminworker"), model);
    }
    

    Template

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    

    @{ Layout = "WebBase.cshtml"; }

    @{ Html.RenderAction("RenderEditRecord", " Record");} @CurrentPage.GetGridHtml("contentGrid", "bootstrap3")

    The partial view renders without the master page layout, any pointers much appreciated, pulling my hair out!!!

  • Alex Skrypnyk 6131 posts 23950 karma points MVP 7x admin c-trib
    Nov 30, 2018 @ 00:44
    Alex Skrypnyk
    0

    Hi Tom

    Use just view, not PartialView, use View();

    Thanks,

    Alex

  • Tom Bruce 122 posts 506 karma points
    Nov 30, 2018 @ 01:14
    Tom Bruce
    0

    Hi Alex, my PartialView inherits from @inherits UmbracoViewPage

    And my template inherits from @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

    I receive the following error when i try to return a view()

    Cannot bind source type Models.ApplicationViewModel to model type Umbraco.Web.Models.RenderModel.

    How can I return my viewmodel?

  • Tom Bruce 122 posts 506 karma points
    Nov 30, 2018 @ 01:35
    Tom Bruce
    0

    Hi everyone, if I return the view without my model I receive a new error;

    Insufficient stack to continue executing the program safely. This can happen from having too many functions on the call stack or function on the stack using too much stack space.

  • Nik 1591 posts 7148 karma points MVP 6x c-trib
    Nov 30, 2018 @ 09:15
    Nik
    0

    Hi Tom,

    A couple of questions for you,

    1) The "Edit" view, are you expecting that to be a whole page or are you expecting it to be a partial view that is rendered within a page?

    2) I'm assuming the Edit view is a form of some description that are you posting back once completed is that correct?

    Nik

  • Tom Bruce 122 posts 506 karma points
    Nov 30, 2018 @ 13:20
    Tom Bruce
    0

    Hi Nik, regarding the Edit view, I have a whole page, I was hoping to display the partial view inside the whole page.

    Is it possible to display a partial view with a master template?

    Tom

  • Nik 1591 posts 7148 karma points MVP 6x c-trib
    Nov 30, 2018 @ 13:49
    Nik
    0

    Hi Tom,

    Not in the way you are trying to link to it I don't believe.

    What you would need to do is link to you "edit" page (assuming it is a page in Umbraco) and then within that page call the action to render the partial view rather than link to an action that returns a partial view.

    This would, I believe, be similar to the required behaviour in a default .Net MVC application.

    It could be worth having a read of the following, which might help you achieve what you are after :-) https://our.umbraco.com/Documentation/Reference/Templating/Mvc/forms

    Thanks

    Nik

  • Tom Bruce 122 posts 506 karma points
    Nov 30, 2018 @ 14:17
    Tom Bruce
    0

    Hi Nik, yes the page is an Umbraco page, do mean something like this,

    <a href='http://localhost:56973/2162?Id=" + Id + "'>Edit</a>
    

    Then the page will call the action to render the partial view, is this what you mean?

  • Nik 1591 posts 7148 karma points MVP 6x c-trib
    Nov 30, 2018 @ 14:23
    Nik
    100

    Kind of.

    What I would expect is something along the lines of you having a generic "Edit" page set up in Umbraco that is on the url (for example) /edit

    Then in the page where you are trying to put the "edit" link you have something like:

    <a href="/edit?ref=@idOfContentIWantToEdit">Edit</a>
    

    Then on the edit page you have something like the following

    var targetEditId = Request.Params["ref"];
    
    @Html.Action("RenderEditRecord", "Record", new {RecordId = targetEditId})
    

    This would mean that your RenderEditRecord action doesn't need to be passed an ApplicationViewModel any more it be passed only the record id.

    It should then render your partial view into your edit page .

    You could also put logic in the edit page that if someone was to browse to it without passing in a record ID it could display a generic message instead of trying to render the form.

    Does that make sense?

    Nik

  • Tom Bruce 122 posts 506 karma points
    Nov 30, 2018 @ 14:57
    Tom Bruce
    1

    Thanks worked a treat :)

  • Nik 1591 posts 7148 karma points MVP 6x c-trib
    Nov 30, 2018 @ 15:04
    Nik
    1

    No worries :-) Happy to have helped.

Please Sign in or register to post replies

Write your reply to:

Draft