0

What is the best approach for exposing a global variable from an MVC Layout Master to a child view.

Here's the flow:

Layout:

var myPlugin = $("#myPlugiv").MyPlugin();

Child View:

var returnValue = myPlugin.GetValue();

This obviously works since the myPluin variable is visible to the child view, but is there another recommended pattern for sharing global values between Master Layout and the child view?

1 Answer 1

2

You could always organize them into a namespace to limit the number of globally scoped variables. Something like:

window.ViewModel = {
    myPlugin: $('#myPlugin').MyPlugin()
};

var returnValue = ViewModel.myPlugin.GetValue();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.