Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 30th, 2012  |  syntax: None  |  size: 1.70 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Pass JavaScript to a Partial View
  2. <%@ Control Language="C#"
  3.             Inherits="System.Web.Mvc.ViewUserControl<ToolButton>" %>
  4.  
  5. <%@ Import Namespace="Models.Shared" %>
  6.  
  7. <script src="<%= Url.Content("~/Scripts/Utility/toolbutton.js") %>" type="text/javascript"></script>
  8.  
  9. <script type="text/javascript">
  10.  
  11.    $(function () {
  12.       $('<%: String.Format("#{0}", Model.Id) %>').toolbutton({ 'onClick': function () { alert('xyz'); } });
  13.    });
  14.  
  15. </script>
  16.  
  17. <div id="<%: Model.Id %>" class="tool-button"></div>
  18.        
  19. <%@ Control Language="C#"
  20.             Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<ToolButton>>" %>
  21.  
  22. <%@ Import Namespace="Models.Shared" %>
  23.  
  24. <div class="tool-panel">
  25.    <table>
  26.       <tbody>
  27.          <tr>
  28.  
  29.             <% foreach (var toolButton in Model)
  30.                { %>
  31.                   <td><% Html.RenderPartial("ToolButton", toolButton); %></td>
  32.             <% } %>
  33.  
  34.          </tr>
  35.       </tbody>
  36.    </table>
  37. </div>
  38.        
  39. <script type="text/javascript">
  40.  
  41.   $(function () {
  42.     $('<%:String.Format("#{0}", Model.Id) %>').toolbutton({
  43.         'onClick': function () {
  44.             if (typeof <%=String.Format("OnClickFor{0}", Model.Id)%> == 'function') {
  45.               <%: String.Format(OnClickFor{0}", Model.Id) % >();
  46.             }
  47.         });
  48.   });
  49.  
  50. </script>
  51.  
  52. <div id="<%: Model.Id %>" class="tool-button"></div>
  53.        
  54. <script type="text/javascript">
  55.   var onClickFor01 = function(){alert('Clicked onClickFor01 ')}
  56. </script>
  57.  
  58. <div class="tool-panel">
  59.    <table>
  60.       <tbody>
  61.          <tr>
  62.  
  63.             <% foreach (var toolButton in Model)
  64.                { %>
  65.                   <td><% Html.RenderPartial("ToolButton", toolButton); %></td>
  66.             <% } %>
  67.  
  68.          </tr>
  69.       </tbody>
  70.    </table>
  71. </div>