Copied to clipboard

Flag this post as spam?

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


  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Mar 12, 2016 @ 09:07
    Michaël Vanbrabandt
    0

    CurrentPage is not available in a surface controller partial view

    Hi,

    I have created a AccountSurfaceController which has a ActionMethod to render the login modal.

    This modal contains a link to the register content node.

    How can I get the url to my register page in my partial view of the surface controller?

    I can't access the current page like @CurrentPage.

    My partial view:

    @model Prosec.Models.AccountLoginViewModel
    
    @using Prosec.Controllers;
    
    <div class="modal fade" id="modal-account-login" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-sm">
            <div class="modal-content">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <div class="modal-header">
                    <h4 class="modal-title">Welkom terug</h4>
                </div>
    
                @using (Html.BeginUmbracoForm<AccountSurfaceController>("MemberLogin", "AccountSurface", new { @id = "formLogin", @class = "form-horizontal", role = "form" }))
                {
                    @Html.AntiForgeryToken()
    
                    <div class="modal-body">
    
                        <div class="validations-output"></div>
    
                        <div class="form-group">
                            <div class="col-sm-12">
                                @Html.TextBoxFor(m => m.Username, new { @class = "form-control", placeholder = "Gebruikersnaam..." })
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-12">
                                @Html.PasswordFor(m => m.Password, new { @class = "form-control", placeholder = "Wachtwoord..." })
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-6">
                                <div class="form-checkbox">
    
                                    @Html.CheckBoxFor(m => m.RememberMe, new { @class = "" })
    
                                    <label for="RememberMe">Mij onthouden?</label>
    
                                </div>
                            </div>
                        </div>
                        <button type="submit" class="btn btn-primary btn-lg"><span>Aanmelden</span></button>
                    </div>
                    <div class="modal-links">
                        <ul>
                            <li><a class="account-forgot-pwd-btn" href="#"><i class="fa fa-caret-right"></i>Wachtwoord vergeten?</a></li>
                            <li>
    
                                // Here I need to get the url of the register page content node......................
                                <a href="#"><i class="fa fa-caret-right"></i>Account registreren?</a>
    
                            </li>
                        </ul>
                    </div>
                }
    
            </div>
        </div>
    </div>
    

    /Michael

  • Dennis Adolfi 1082 posts 6450 karma points MVP 6x c-trib
    Mar 12, 2016 @ 09:20
    Dennis Adolfi
    0

    Add a property to your AccountLoginViewModel named 'CurrentPage' of type IPublishedContent and pass it on from the SurfaceController.

    Then you can access it from Model.CurrentPage in your partial view.

  • Dennis Adolfi 1082 posts 6450 karma points MVP 6x c-trib
    Mar 12, 2016 @ 10:21
    Dennis Adolfi
    0

    Or you only need the URL to the Register page then add a string property on your viewmodel an populate it with the CurrentPage.Url value from your AccountSurfaceController before you return the partialview.

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Mar 12, 2016 @ 10:44
    Dave Woestenborghs
    105

    Hi Michaël,

    You can also do

    @inherits UmbracoViewPage<Prosec.Models.AccountLoginViewModel>
    

    instead of

    @model Prosec.Models.AccountLoginViewModel
    

    Then you will have access to the Umbraco Helper in your view.

    You can use this to get the current IPublished content item :

     @Umbraco.AssignedContentItem
    

    Dave

  • Dennis Adolfi 1082 posts 6450 karma points MVP 6x c-trib
    Mar 12, 2016 @ 10:49
    Dennis Adolfi
    0

    I had no idea that that you could do that, thats great. I´m gonna start using that one! :)

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Mar 12, 2016 @ 10:51
    Dave Woestenborghs
    1

    Hi dennis,

    You can read the article I wrote for the Christmas calendar. I explain the differences between the template types in Umbraco : http://24days.in/umbraco/2015/strongly-typed-vs-dynamic-content-access/

    And also difference between dynamic and strongly typed content access.

    Dave

  • Dennis Adolfi 1082 posts 6450 karma points MVP 6x c-trib
    Mar 12, 2016 @ 10:52
    Dennis Adolfi
    0

    Awsome, thank you! I´ll defenetly look at it! :)

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Mar 12, 2016 @ 10:56
    Michaël Vanbrabandt
    0

    Nice one didn't know about that!

    Thanks for this solution

    /Michael

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Mar 12, 2016 @ 10:58
    Dave Woestenborghs
    0

    Hi Michaël,

    Don't forget to mark the topic as solved. So others can find the solution as well.

    Dave

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Mar 12, 2016 @ 11:07
    Michaël Vanbrabandt
    0

    I know, I was first impleting it in my solution and test it.

    Again thanks for the intel!

    /Michael

  • Dennis Adolfi 1082 posts 6450 karma points MVP 6x c-trib
    Mar 12, 2016 @ 14:01
    Dennis Adolfi
    0

    Great post Dave (http://24days.in/umbraco/2015/strongly-typed-vs-dynamic-content-access/)!

    Perfect saturday read. :)

  • 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