Question

My goal is to add the full register shape in a modal.

To achieve this, I add my content in my layout:

WorkContext.Layout.ModalFirst.Add(New.Register(), "15");

My register view looks nice with bootstrap modal.

Everything seems to work.

BUT

I use the contrib.Profile and itWorks.ExtendedRegistration in order to display adding field in profile and in registration.

These fields doesn't show up.

I debug and put some breakpoints into controller that display register. But no one fire up. So my conclusion is that the Ad Hoc shape directly inject the cshtml.

My question is:

How to add into the Shape the Model.UserProfile that is needed to display added fields ?

@using (Html.BeginFormAntiForgeryPost()) { 
<fieldset>
    <legend>@T("Account Information")</legend>
    <div>
        <label for="username">@T("Username:")</label>
        @Html.TextBox("username") 
        @Html.ValidationMessage("username") 
    </div>
    <div>
        <label for="email">@T("Email:")</label>
        @Html.TextBox("email") 
        @Html.ValidationMessage("email") 
    </div>
    <div>
        <label for="password">@T("Password:")</label>
        @Html.Password("password") 
        @Html.ValidationMessage("password") 
    </div>
    <div>
        <label for="confirmPassword">@T("Confirm password:")</label>
        @Html.Password("confirmPassword") 
        @Html.ValidationMessage("confirmPassword") 
    </div>
        @if (Model.UserProfile != null)
        {
            <br />
            <fieldset>
                <legend>@WorkContext.CurrentSite.SiteName</legend>
            @Display(Model.UserProfile)
                </fieldset>
        }
    <div>
        <button class="primaryAction" type="submit">@T("Register")</button>
    </div>
</fieldset>
} 

Edit:

My problem comes only from the fact that I dynamically loads the shape.

If I type url to directly called the shape : http://DomainName.com/Users/Account/Register my added fields are displayed.

If I use the Shape Ad Hoc : WorkContext.Layout.ModalFirst.Add(New.Register(), "15");

It's launch the same shape (same cshtml) but my added fields are not displayed.

I know why, it's simply don't pass into the controller that injects the UserProfile into the shape:

var shape = _orchardServices.New.Register();

        var user = _orchardServices.ContentManager.New("User");
        if (user != null)
        {
            shape.UserProfile = _contentManager.BuildEditor(user);
        }

        return new ShapeResult(this, shape);

So the question is How to do these lines further into the layout view ?

Was it helpful?

Solution 2

Finally I found the way to use same lines in my cshtml:

var orchardServices = WorkContext.Resolve<IOrchardServices>();
var contentManager = WorkContext.Resolve<IContentManager>();

var shape = orchardServices.New.Register();

var user = orchardServices.ContentManager.New("User");
if (user != null)
{
    shape.UserProfile = contentManager.BuildEditor(user);
}

WorkContext.Layout.ModalFirst.Add(shape, "15");

And in my Register.cshtml on my own module that extends Orchard.User I have these lines:

@if (Model.UserProfile != null)
{
    <div class="col-md-2"></div>
    @Display(Model.UserProfile)
    <div class="col-md-2"></div>
}

And now everything is working :)

OTHER TIPS

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top