Afshin Ghazi
Afshin Ghazi

Reputation: 2990

Override variable in Razor view

Newly working with razor view and appreciate any suggestions. I have the following in the view:

Script.Require("Accounts");
var o = sidePanel.Entities.ToString(WorkContext.CurrentUser, false);

var t = sidePanel.Entities.Title;
<text>
    <article class="widget-aside-right widget-accounts-side-widget widget">
        <accounts-side-widget @o title="@t" />
    </article>
</text>

and the C# toString method is:

public string ToString(IUser user, bool isOpenDynamic = true)
{
    // todo (tba 11/3/15): why is groups always included?
    string options = (AllAccounts ? " allaccounts" : string.Empty)
                     + (EntityGroups ? " groups" : string.Empty)
                     + (Balance ? " balance" : string.Empty)
                     + (Number ? " number" : string.Empty)
                     + " isOpen=" + (IsOpen && isOpenDynamic)
                     + (ClientCode ? " clientCode" : string.Empty)
                     + (BaseCurrency ? " baseCurrency" : string.Empty)
                     + " missingdatareportid=" + MissingDataReportId
                     + (ReportBook && user.HasPermission(PermissionType.ReportBook) ? " reportbook" : string.Empty)
                     + (AccountDetailPopup ? " details" : string.Empty);

    return options;
}

I cannot change the variable in the backend because it will affect many other clients using the same backend but the view is specific to this client. Therefore, I need to be able to change the value of a certain variable (isOpen) in the view and not in the backend.

Read about setting the variable using Javascript and JQuery but saw this isn't a good idea.

Upvotes: 0

Views: 163

Answers (1)

DrMistry
DrMistry

Reputation: 331

Just write another version of the ToString(..) method for that specific client, calling it ToStringForABCInc(...) That way, you maintain the existing logic and views for other clients and have the specific view and logic for the client with the special requirement.

Upvotes: 1

Related Questions