Click here to Skip to main content
12,999,417 members (84,377 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi Guys,

Quick question, in webforms, you extend your i mean
public class MyPage : Page

and you can write to your page header using
 protected override void OnPreRender(EventArgs e)
  var jqueryitems = new Dictionary<string, string>
                                      {"6", "jquery.common.js"},
                                      {"7", "jquery.autocomplete.js"},
                                         {"8", "jquery.autocomplete.common.js"},
                                      {"9", "json2.js"}
            foreach (KeyValuePair<string, string> pair in jqueryitems)
                var commonJquery = new HtmlGenericControl("script");
                commonJquery.Attributes.Add("type", "text/javascript");
                commonJquery.Attributes.Add("language", "javascript");
                commonJquery.Attributes.Add("src", string.Format("/common/home/client/jQuery/{0}", pair.Value));
                this.Header.Controls.AddAt(int.Parse(pair.Key), commonJquery);

In mvc how would you go about doing the same technique,but this time using BaseControler or controler class?
Posted 23-Apr-13 21:42pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The simplest way I can imagine right now is to use a combination of sections and ViewBag. You can use the sections (see:[^]) to make a header section in the layout. Than you can add a dictionary like you mentioned (or something similar) to ViewBag to store (gather) script reference needs during execution of the actions. And you can use the data gathered in that object to render in the view the necessary script references into the header section.
You can make a helper class to have related tasks organized tidy.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170624.1 | Last Updated 24 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100