title: How to execute JavaScript function on PartialView load in MVC 3
body: <pre><code>\\code
  public ActionResult mapPartial(DataTable dt)
          {
              string strEvents = "[";
              foreach (DataRow row in dt.Rows)
              {
                  strEvents += "[" + row["Lat"].ToString() + ", " + row["Long"].ToString() + ", " + "\"" +
                  row["LastName"].ToString() + row["DateOfBirth"].ToString() + "\"" + "],";
              }
              strEvents = strEvents.Remove(strEvents.LastIndexOf(","));
              strEvents += "]";
  
              ViewBag.locpoints = strEvents;
  
              return PartialView(dt);
          }
  
  //in the partial view page
  &lt;script type="text/javascript"&gt;
         function mapInit(Viewbag.locpoints) {
  
                var arr = $.parseJSON(Viewbag.locpoints);
                //more code which assigns a map to div map below 
         }
  &lt;/script&gt;
  
  &lt;div id="map" class="map"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>How can i call the JS function immediately to render my map when the partial view is loaded. The partial method in the controller returns a string which is used as parameter in the JS function. Hope it makes sense.  </p>