I have AccountsController in my solution with two methods ExportData and DeleteAccount.

I have created two separate Controller Renderings with similar code:

@using System.Web.Mvc
@using System.Web.Mvc.Html
@using Sitecore.HabitatHome.Foundation.Alerts.Models
@using Sitecore.HabitatHome.Foundation.Dictionary.Extensions
@using Sitecore.HabitatHome.Foundation.SitecoreExtensions.Extensions
@using Sitecore.Mvc
@using Sitecore.Mvc.Configuration

@using (Html.BeginRouteForm(MvcSettings.SitecoreRouteName, FormMethod.Post, new { @class = "form-signin" }))

    <div class="form-group">
        <input type="submit" class="btn btn-info btn-md btn-block" value="@Html.Sitecore().Dictionary("/Accounts/Data Protection/Export Data", "Export Data")" />


Controller Renderings look at the end like this:

enter image description here

In every rendering only one button is rendered.

When I keep it like this only the second method is called (DeleteAccount) even though I have clicked on first button (Export Data). I would assume that the proper method from Controller is called.

When I remove second rendering from the page. Everything is working as expected.

When I add @Html.Sitecore().FormHandler("Accounts","ExportData") or @Html.Sitecore().FormHandler("Accounts","DeleteAccount") inside of using statement, proper method is called however Tracker.Current is null in this case.

How can I create Controller Renderings to support scenario to have them on same page and proper method from Controller is called based on what I have clicked and Tracker.Current is correct?

I had these two Controller Renderings before as one but the problem was that I was loosing Tracker.Current and Tracker.Current?.Contact when I clicked on button. I do not want to add StartingTracking to overcome this as it feels like a small hack.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.