开发者

Converting to Mvc, ToolkitScriptManager ServiceReference

So, I'm working in a hybrid web app/mvc application. Trying to do all new stuff in MVC and slowly changing some old webforms parts when there is time or a need for it. Using Razor.

Currently I'm trying to bring some old javascript into an mvc page and I'm having some troubles with the ServiceReferences. Is there a way to get these working in Razor, I really don't want to have to re-write this js file, seems how it's about 1500 lines.

I've got references to

<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js">   </script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/mvc/2.0/MicrosoftMvcAjax.js"></script>

I'm guessing there must be some way to write this registration somewhere? In webForms it worked like this, for reference:

<ajaxToolkit:ToolkitScriptManager ID="cnvScriptManager" EnablePartialRendering="true" ScriptMode="Release" LoadScriptsBeforeUI="true" CombineScripts="true" CombineScriptsHandlerUrl="~/CombineScriptsHandler.ashx" runat="server">
                <Services>
                    <asp:ServiceReference Path="~/ux/controls/util.asmx" />
                    <asp:ServiceReference Path="~/ux/controls/menu/menu.asmx" />
                    <asp:ServiceReference Path="~/ux/开发者_JAVA百科controls/menu/list.asmx" />
                    <asp:ServiceReference Path="~/ux/controls/menu/tag.asmx" />
                    <asp:ServiceReference Path="~/ux/controls/canvas/filter/filter.asmx" />
                    <asp:ServiceReference Path="~/ux/controls/canvas/export/export.asmx" />
                </Services>
            </ajaxToolkit:ToolkitScriptManager>

and then in the js you could do this nonsensical magic:

Xyz.Api.ListUXService.Fill(listParams, onFillListSuccess, onFailure, List);

I would love to have the time to convert it to jQuery and MVC, but, I don't :)


in your razor view add a reference to a partial view, this partial view should be made with the webforms view engine

<body>
    @Html.Partial("_ScriptManager")
</body>

and then just put your scriptmanager in said partial view

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<form id="form1" runat="server">
<ajaxtoolkit:toolkitscriptmanager id="myScriptManager" enablepartialrendering="true"
    scriptmode="Release" loadscriptsbeforeui="true" combinescripts="true" combinescriptshandlerurl="~/CombineScriptsHandler.ashx"
    runat="server">
                <Services>
                    <asp:ServiceReference Path="~/ux/controls/util.asmx" />
                    <asp:ServiceReference Path="~/ux/controls/menu/list.asmx" />
                    <asp:ServiceReference Path="~/ux/controls/menu/tag.asmx" />
                    <asp:ServiceReference Path="~/ux/controls/canvas/dialogs.asmx" />
                </Services>
</ajaxtoolkit:toolkitscriptmanager>
</form>

Now before all the mvc purists get mad, I want to add that I do not recommend doing this, this goes against MVC, but it works and if you don't have time to change a ton of legacy code, here is a solution.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜