
Untitled
By: a guest on
Jun 30th, 2012 | syntax:
None | size: 1.70 KB | hits: 10 | expires: Never
Pass JavaScript to a Partial View
<%@ Control Language="C#"
Inherits="System.Web.Mvc.ViewUserControl<ToolButton>" %>
<%@ Import Namespace="Models.Shared" %>
<script src="<%= Url.Content("~/Scripts/Utility/toolbutton.js") %>" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('<%: String.Format("#{0}", Model.Id) %>').toolbutton({ 'onClick': function () { alert('xyz'); } });
});
</script>
<div id="<%: Model.Id %>" class="tool-button"></div>
<%@ Control Language="C#"
Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<ToolButton>>" %>
<%@ Import Namespace="Models.Shared" %>
<div class="tool-panel">
<table>
<tbody>
<tr>
<% foreach (var toolButton in Model)
{ %>
<td><% Html.RenderPartial("ToolButton", toolButton); %></td>
<% } %>
</tr>
</tbody>
</table>
</div>
<script type="text/javascript">
$(function () {
$('<%:String.Format("#{0}", Model.Id) %>').toolbutton({
'onClick': function () {
if (typeof <%=String.Format("OnClickFor{0}", Model.Id)%> == 'function') {
<%: String.Format(OnClickFor{0}", Model.Id) % >();
}
});
});
</script>
<div id="<%: Model.Id %>" class="tool-button"></div>
<script type="text/javascript">
var onClickFor01 = function(){alert('Clicked onClickFor01 ')}
</script>
<div class="tool-panel">
<table>
<tbody>
<tr>
<% foreach (var toolButton in Model)
{ %>
<td><% Html.RenderPartial("ToolButton", toolButton); %></td>
<% } %>
</tr>
</tbody>
</table>
</div>