Reputation: 40182
When upgrading an ASP.NET 4 (3.5 rendering) WebForms application to MVC 3, how can I get the same JavaScript generated by ScriptManager
for a ServiceReference
of an ASMX file?
I have an ASMX web service file that is used extensively via the JavaScript ScriptManager
generates for it. The existing code needs to continue to work but you can't use ScriptManager
in an MVC view. Is there a way to have the JavaScript code automatically generated in ASP.NET MVC?
Here is how I have it in my Default.aspx
WebForm page:
<asp:ScriptManager ID="sm" runat="server">
<Services>
<asp:ServiceReference Path="/WebService.asmx" />
</Services>
</asp:ScriptManager>
Upvotes: 2
Views: 2848
Reputation: 40182
I had to add MicrosoftAjax.js
and WebService.asmx/js
to the page.
<script src="@Url.Content("~/Scripts/MicrosoftAjax.js")" type="text/javascript"></script>
<script src="/WebService.asmx/js" type="text/javascript"></script>
Note the trailing /js
in /WebService.asmx/js
.
Appending /js
to the path of the .asmx
file gives you the Javascript for your webservice. Likewise, appending /jsdebug
gives you the verbose Javascript for debugging purposes.
Upvotes: 3