开发者

Does MVCScriptManager from CodePlex work with ViewUserControls?

I tried the MVCScriptManager from CodePlex and it seems to work well until you try to use it in conjunction with a ViewUserControl.

When it is used in this type of scenario it gives the following error.

A ScriptManager with RenderMode set to Master is not present. Such ScriptManager must precede one with RenderMode set to Slave.

There is a ScriptManager with render mode set to "Master" in the header of the Site.Master page but it appears that the partial views are rendered first.

Is there any way to work around this problem?

=== Master Page ====

<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>

<!DOCTYPE html PUBLIC 
"-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
    <link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
    <mvc:ScriptManager ID="ScriptManager1" RenderMode="Master" 
    runat="server" EnableHttpCompression="true" EnableHttpExpiration="true"
    HttpExpirationInDays="30">
        <Scripts>
            <mvc:Scrip开发者_运维知识库tReference EnableCrunching="true" 
             Path="~/Scripts/jquery-1.3.2.js" />
        </Scripts>
    </mvc:ScriptManager>
</head>

<body>
    <div class="page">

        <div id="header">
            <div id="title">
                <h1>My MVC Application</h1>
            </div>

            <div id="logindisplay">
                <% Html.RenderPartial("LogOnUserControl"); %>
            </div> 

==== LogOnUserControl.ascx ====

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%
    if (Request.IsAuthenticated) {
%>
        Welcome <b><%= Html.Encode(Page.User.Identity.Name) %></b>!
        [ <%= Html.ActionLink("Log Off", "LogOff", "Account") %> ]
<%
    }
    else {
%> 
        [ <%= Html.ActionLink("Log On", "LogOn", "Account") %> ]
<%
    }
%>

    <mvc:ScriptManager ID="ScriptManager1" RenderMode="Slave" 
     runat="server" EnableHttpCompression="true" 
     EnableHttpExpiration="true" HttpExpirationInDays="30">
        <Scripts>
            <mvc:ScriptReference EnableCrunching="true"
             Path="~/Scripts/SampleScript_LoginViewUserControl.js" />
        </Scripts>
    </mvc:ScriptManager>


I have been using the MVC ScriptManager for a while now and the answer is no, you cannot add it to a partial view. You must define the necessary script includes in a .ASPX View.

<mvc:ScriptManager RenderMode="Slave" runat="server" EnableHttpExpiration="true" HttpExpirationInDays="30">
    <Scripts>
        <mvc:ScriptReference Path="~/Content/Js/jquery/jquery.jgrowl.min.js" />
        <mvc:ScriptReference Path="~/Content/Js/core/script.min.js" />
        <mvc:ScriptReference Path="~/Content/Js/core/json2.min.js" />
    </Scripts>
</mvc:ScriptManager>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜