Welcome to Vortx Community Forum, where you can ask questions and receive answers from the staff at Vortx and other members of the community.

If you had a user account on our previous forums website, you will need to register a new account here.

Learn more about...


Add custom code to Model for all pages

I'm in the process of upgrading my Aspdotnetstorefront site from version 9.x to 10.x. In my original skin file, I have a bit of code that checks the users customer level and displays some content accordingly. Previously, I was just using 'ThisCustomer.CustomerLevel' to perform that check, but with the new MVC templating system, that doesn't work anymore. I was able to talk to Storefront support and get a hint at how to replicate this by adding some custom code to the Model and using something like "Model.CustomerLevelID" to perform the same check. Unfortunately, I was not told what model would be appropriate to use, as this code needs to be applied to all pages. I was able to test the code out using the Home View Model/template, so I know it works. But what model would I need to use in order to apply this to all pages on the site?

asked Sep 8, 2017 in MultiStore by DDM486 (555 points)

1 Answer

+1 vote
Best answer
I guess it depends on where you wanting to do this. Cause depending on where it may make more more sense to make your own controller and model and calling the view with Html.Action to call your custom controller.

I will warn that you don't want to add to many html.action since that can add overhead compared tojust adding to fields to a existing model. An example of this is the user links and login links and mini cart links can all be consolidated to one view. Which doing the combiing of view calls does boost load time performance. This improvment does show  using the compare feature for performance profiler built into vs.net . I say all this not to deter you from using Html.Action. It is more that I want to share the experances I found when profiliing perforance.
answered Sep 8, 2017 by mmcgeachy (5,045 points)
selected Sep 11, 2017 by DDM486
Awesome, thank you for the tip! As you suggested, I created a custom controller/model and used the HTML Action in my skin to get the view and it worked like a charm! Thanks again for the help!