Firefox 6 Infinite Page Refresh With Page With Hash Tags

Turns out, this is an issue with an old version of MicrosoftAjax.js (the one that comes installed with Asp.Net MVC 2). Open up the MicrosoftAjax.debug.js file and check the file version number. The top of this file will look like this if this is your problem: // Name: MicrosoftAjax.debug.js // Assembly: System.Web.Extensions // Version: 4.0.0.0 … Read more

Need an ASP.NET MVC long running process with user feedback

Here’s a sample I wrote that you could try: Controller: public class HomeController : AsyncController { public ActionResult Index() { return View(); } public void SomeTaskAsync(int id) { AsyncManager.OutstandingOperations.Increment(); Task.Factory.StartNew(taskId => { for (int i = 0; i < 100; i++) { Thread.Sleep(200); HttpContext.Application[“task” + taskId] = i; } var result = “result”; AsyncManager.OutstandingOperations.Decrement(); AsyncManager.Parameters[“result”] … Read more

ActionLink htmlAttributes

The problem is that your anonymous object property data-icon has an invalid name. C# properties cannot have dashes in their names. There are two ways you can get around that: Use an underscore instead of dash (MVC will automatically replace the underscore with a dash in the emitted HTML): @Html.ActionLink(“Edit”, “edit”, “markets”, new { id … Read more

ModelState.AddModelError – How can I add an error that isn’t for a property?

I eventually stumbled upon an example of the usage I was looking for – to assign an error to the Model in general, rather than one of it’s properties, as usual you call: ModelState.AddModelError(string key, string errorMessage); but use an empty string for the key: ModelState.AddModelError(string.Empty, “There is something wrong with Foo.”); The error message … Read more

How do I configure ASP.NET MVC routing to hide the controller name on a “home” page?

Try this: private void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”); routes.MapRoute(“default”, “{controller}/{action}/{id}”, new { action = “index”, id = “” }, // Register below the name of all the other controllers new { controller = @”^(account|support)$” }); routes.MapRoute(“home”, “{action}”, new { controller = “device”, action = “index” }); } e.g. /foo If foo is not a controller … Read more

Jquery dialog partial view server side validation on Save button click

You should try unobstrusive Client side Validation Example JQuery $(‘#BTN’).click(function () { var $formContainer = $(‘#formContainer’); var url = $formContainer.attr(‘data-url’); $formContainer.load(url, function () { var $form = $(‘#myForm’); $.validator.unobtrusive.parse($form); $form.submit(function () { var $form = $(this); if ($form.valid()) { $.ajax({ url: url, async: true, type: ‘POST’, data: JSON.stringify(“Your Object or parameter”), beforeSend: function (xhr, opts) … Read more

When `PostAuthenticateRequest` gets execute?

According to the documentation: Occurs when a security module has established the identity of the user. … The PostAuthenticateRequest event is raised after the AuthenticateRequest event has occurred. Functionality that subscribes to the PostAuthenticateRequest event can access any data that is processed by the PostAuthenticateRequest. And here’s the ASP.NET Page Life Cycle. But because your … Read more

RegularExpressionAttribute – How to make it not case sensitive for client side validation?

I created this attribute which allows you to specify RegexOptions. EDIT: It also integrates with unobtrusive validation. The client will only obey RegexOptions.Multiline and RegexOptions.IgnoreCase since that is what JavaScript supports. [RegularExpressionWithOptions(@”.+@example\.com”, RegexOptions = RegexOptions.IgnoreCase)] C# public class RegularExpressionWithOptionsAttribute : RegularExpressionAttribute, IClientValidatable { public RegularExpressionWithOptionsAttribute(string pattern) : base(pattern) { } public RegexOptions RegexOptions { get; … Read more

Are

the colon syntax means you’ll be html encoded automatically: http://haacked.com/archive/2009/09/25/html-encoding-code-nuggets.aspx They couldn’t just html encode all the existing <%= blocks, because things that are already properly encoded (which is hopefully most of the projects out there) would look strange.

Best practice for ASP.NET MVC resource files

You should avoid App_GlobalResources and App_LocalResources. Like Craig mentioned, there are problems with App_GlobalResources/App_LocalResources because you can’t access them outside of the ASP.NET runtime. A good example of how this would be problematic is when you’re unit testing your app. K. Scott Allen blogged about this a while ago. He does a good job of … Read more