How do I use MicrosoftMvcValidation.js without having to include MicrosoftAjax.js? - asp.net-mvc

It looks like there's an issue in MVC 2 RC1 if you want to use jQuery.Validate but not the main Microsoft AJAX - which is 25kb even when gzipped.
According to Phil Haack you're supposed to be able to just include these scripts:
<script src="/Scripts/jquery-1.3.2.js" type="text/javascript"></script>
<script src="/Scripts/jquery.validate.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcJQueryValidation.js" type="text/javascript">
Unfortunately in some reorganization they did between Beta and RC - you also now need to include MicrosoftAjax.js which defines the Type prototype functions that are used by MicrosoftMvcJQueryValidation.js (the first line is Type.registerNamespace('Sys.Mvc'); which is defined in MicrosoftAjax.js)
Has anyone already extracted out the necessary code from MicrosoftAjax.js that is needed?
I'll have to do it sooner or later but if anyone has already done it that would help a lot!

Aha!
Looks like MicrosoftMvcValidation.js is NOT the file needed for jQuery.validate.
You need to use the very similarly named MicrosoftMvcJQueryValidation.js. This has no dependency on Microsoft.Ajax.js.
The latest version of MicrosoftMvcJQueryValidation.js is available in the futures download project. It isn't included in the normal download - hence my confusion.

Instead of jumping through hoops to get this working, you might want to look into letting Microsoft/Google serve the AJAX library for you. This would likely give you a speed advantage. And a good chance that the library will already exist on the client's machine.

Related

Where to add ES6-Promise Script Tag In ASP.net MVC?

I'm using the sample here to embed a Power BI report into a web application.
The application compiles properly, but I'm getting an error involving Promises. I've tracked down the solution here. It seems that I need to add the following somewhere in my application:
<script src="https://npmcdn.com/es6-promise#3.2.1"></script>
However, I have absolutely no idea where this script tag should go. Any suggestions? Thank you.
The es6-promise library is a polyfill for Promises, mostly used in IE.
If you need it, you just need to put it anywhere in your <head> tag, preferably before your <script src='.../powerbi.js>.
For more info on es6-promise: https://github.com/stefanpenner/es6-promise

Tutorial: Server Broadcast with SignalR 2

I read this excellent tutorial : http://www.asp.net/signalr/overview/getting-started/tutorial-server-broadcast-with-signalr.
I then downloaded the NuGet example package Microsoft.AspNet.SignalR.Sample 2.2.0 (https://www.nuget.org/packages/microsoft.aspnet.signalr.sample), and then I created new asp.net mvc 5 project with vs 2015 with an index page.
I assume that app.MapSignalR() is called in the Startup.Configuration method.
Like lots of people I got the error: ticker.client is undefined.
The real problem is the var ticker = $.connection.stockTicker, is always null because $.connection has no stockTicker property defined - because the hub can't instantiate it.
Does anybody know the reason for this error?
The orignial tutorial is http://www.asp.net/signalr/overview/getting-started/tutorial-server-broadcast-with-signalr I hosted my sample project zip to my open onedrive : https://onedrive.live.com/embed?cid=11357B31E08CCFEE&resid=11357B31E08CCFEE%21107&authkey=ALMOtmTFdCdsyV8
The "SignalR.Sample" directory content in the solution is the basic Template to integrate in asp.net mvc 4/5/6 project. So I integrate it in Views/Home/Index.cshtml page. Js refernces are in file Views/Shared/_Layout.cshtml .
Exact problem is var ticker = $.connection.stockTicker is null (no initialize connection done with the server).
If you can help me, i thank you.
Yes, you added the jQuery and Stockticker scripts in your _Layout, but you didn't add the signalr/hubs. The scripts must be loaded in this exact order:
<script src="~/Scripts/jquery.signalR-2.2.0.js"></script>
<script src="~/signalr/hubs"></script>
<script src="~/Scripts/SignalR.StockTicker.js"></script>
Reference:
ASP.NET SignalR Hubs API Guide - JavaScript Client
Make sure that the JavaScript file references in StockTicker.html are correct. That is, make sure that the jQuery version in your script tag (1.10.2 in the example) is the same as the jQuery version in your project's Scripts folder, and make sure that the SignalR version in your script tag is the same as the SignalR version in your project's Scripts folder. Change the file names in the script tags if necessary.
Make sure you have Any CPU as your active solution platform. I switched it to x64 and that made it so SignalR could not load since it had an incorrect platform.

breeze: breeze.angular.js and breeze.savequeuing.js

I am using breeze with angular.
I have upgrade breeze to 1.4.11 and install breeze.angular.js.
The beginnings of a "breeze service" that tells Breeze to
use $q for its promises rather than Q.js
use $http for AJAX calls.
Consequently Breeze no longer requires the jQuery or the Q.js libraries
although non-Breeze code in your app may require either or both.
My problem is that I am still using breeze.savequeuing.js which requires window.Q.
Is there any official solution for this scenario or I have to manually change breeze.savequeuing.js?
It is simple. I can use HACK from angular.breeze.js breeze.Q is $q
We do not yet have an Angular version of breeze.savequeuing. It's on my backlog but way down the list as I try to discourage folks from getting in a situation where it is needed.
You are welcome to write one and contribute it. I recommend writing it as a real ng service rather than a simple Q-for-$q hack. If you like I'll look it over and give you my thoughts.
All the best.
As you mention "discouraging folks ..." I have to mention that the Breeze Todo Sample makes use of breeze.savequeuing.js:
<!-- 3rd party libraries -->
<script src="Scripts/angular.js"></script>
<script src="Scripts/jquery-1.8.3.min.js"></script>
<!-- Q is needed by breeze.savequeuing, not by Breeze-->
<script src="Scripts/q.min.js"></script>
<script src="Scripts/breeze.debug.js"></script>
<script src="Scripts/breeze.angular.js"></script>
<script src="Scripts/breeze.savequeuing.js"></script>
<script src="Scripts/toastr.js"></script>
Perhaps you may use this sample to show everyone to show how not to get into the situation where savequeuing.js is needed :-)

How to include external Javascript file in a JSF page

I want to include the URL of jQuery UI http://code.jquery.com/ui/1.9.0/jquery-ui.js in my JSF page. I saw many questions which said <h:outputScript> should be used, but in none of the answers I saw an example as to how to include an URL. The answers were only relevant if the js file is present in some folder of the project.
Can someone please help where I have to include it in my page?
Just use plain HTML <script> element the usual way.
<script src="http://code.jquery.com/ui/1.9.0/jquery-ui.js"></script>
The <h:outputScript> can only refer local scripts. You'll only miss its dynamic versioning, modularity and relocation advantages, but that should technically not harm for a static and external script.
It's however possible to use a custom ResourceHandler to change the URL of a <h:outputScript> to be an external URL for pure CDN purposes. OmniFaces CDNResourceHandler is such an example.
Unrelated to the concrete problem, PrimeFaces components are built around jQuery/UI. Are you absolutely positive that you need a separate instance of jQuery UI library?

Using a ScriptManager in razor?

Must be a simple question, but I cannot for the life of me figure out how to include a script manager in my view. <asp:ScriptManager /> doesn't work. Anyone know?
ScriptManager is a webforms specific construct, so if you are using MVC, you won't (and shouldn't) be able to use it. You can look at http://mvcscriptmanager.codeplex.com/ if you want something that ports some of the features of the scriptmanager to MVC.
I ran into a similar situation upgrading a project.
For "simple-ish" WCF Ajax services, I was able to get this work by adding:
<script src="#Url.Content("~/Scripts/MicrosoftAjax.js")" type="text/javascript"></script>
<script type="text/javascript" src="#Url.Content("~/Services/SampleService.svc/jsdebug")"></script>
and then create my service object the old fashion way:
var dataService = new SampleService();
dataService.doBar(fooCallback,fooErrorMethod,null);
I haven't tested this is extensively, but Hey, isn't that why the word "kludge" became an official developer term.

Resources