Explicitly use HttpMethod of POST when Making AJAX Calls in IE
I noticed that remote validation I had set up for a web page was not triggering when running the page in IE, but it worked fine in Chrome, Firefox, and Safari.
It turns out that IE caches GET requests, so I had to explicitly use POST to get this to work consistently on all major browsers.
It’s better to be explicit, anyway, so I’m fine with this.
Remote validation attribute example:
[Remote(“CheckDuplicateName”, “Customer”, AdditionalFields = “CustomerId”, ErrorMessage = “This name has already been used. Please choose another name.”, HttpMethod = “POST”)]
jQuery example:
jQuery.ajax({ type: “POST”, url: “/Customer/CheckDuplicate?CustomerId=” + customerId, success: function (result) { … } }, async: false });
Changing the Text of a Toolbar Button in the Telerik ASP.NET MVC Grid Control
If you want to change the default text for a toolbar button (the very generic “Add new record” for the insert button, for example) using Telerik’s ASP.MVC Grid control, here’s a great answer from someone named Aaron (better than Telerik support’s solution) over on the Telerik forum.
Also, see my response, which solves the issue if you’re using GridButtonType.ImageAndText. Otherwise, you’ll lose the icon altogether.
ASP.NET MVC Controller Action Running Twice? This May Be Why.
Ran into a weird situation where a page was always getting loaded twice. I noticed because I had a breakpoint set in the action method, and also saw two calls in Fiddler. Yet this was happening in Chrome, but not in IE (didn’t get around to trying in other browsers before finding the solution).
Apparently, certain browsers will force a reload of a page if the src attribute of the <img> tag is empty, or if it contains an invalid path to an image. It just so happens that this page dynamically specifies the src URL via jQuery after the page loads, so I had set it to an empty string by default.
As soon as I defaulted to a valid URL, the double loading ceased.
Still not sure the reasoning behind this browser (at least Chrome) behavior, so if anyone wants to shed light on this, please let me know.
HtmlHelper.ActionLink Gotcha
In ASP.NET MVC, if you pass in an Object as your fourth parameter to the HtmlHelper.ActionLink method:
HtmlHelper.ActionLink(
string linkText,
string actionName,
string controllerName,
Object routeValues,
Object htmlAttributes)
Don’t forget to explicitly pass null as your fifth parameter (if you don’t intend on setting HTML attributes from this call). Otherwise, you will get a link that ends in something like:
?Length=8
… because there isn’t a four-parameter overload that accepts an Object for routeValues.
This seems to be a common misunderstanding of the overloads for this helper method.
jQuery “Document Ready” Shorthand
Don’t forget that in jQuery:
$(function())
is identical to…
$(document).ready(function())
…only shorter. Not sure if shorter is better in this case, but it’s nice to know you have an option.
Valedictorian speaks out against education system in graduation speech
This takes a LOT of courage, people. Great story. Now what and who will this motivate? What will this change? I just wish this was recorded and posted on YouTube, because that would be what it takes to get this message out to our MTV / ADD society. I’ve read many such sentiments in books and articles, with much proof and studies to back the condemnation of our current system, but when students such as Erica Goldson become aware of what the system is doing to them, it takes this to a new level, and provides a new hope. Edit: This IS on YouTube! Valedictorian speaks out against education system in graduation speech.
We’ve been told the wrong story so many times we believe it: “the reason for a company is profit.” That’s like saying the reason we’re alive is to eat.
– Bruce EckelQuick Book Review
Owned and ran a software consulting company for over a decade, and I must say that Aaron Erickson’s book on the subject is the hands down best: http://bit.ly/9jxsyg
On Teaching
If everyone took the time and effort to explain things like Joel Spolsky does, the world would be a much better place:http://bit.ly/9itIad
