Contents tagged with ASP.NET
666 viewsFormatting JavaScript Date
Formatting DateTime in C# is dead simple – just call ToString() passing in the format string you desire. Doing the same in JavaScript is annoyingly cumbersome. Today, I came across a nice little jQuery plugin that can carry out this mundane task. It’s the jQuery-dateFormat plugin and can be found at
961 views2011 MVP Hat Trick
Got this email today:
6646 viewsASP.NET MVC Gotcha – String as Model
A very common task in ASP.NET MVC is to return a ViewResult from a controller Action. This is usually achieved by a simple:
4495 viewsViewBag can be good…honestly
A lot of people seem to have an allergic reaction towards anything not “strongly typed”. They abhor ViewBag and resent ViewData[“key”] for passing values from the controller to the view. They write viewmodels that aggregate a few other viewmodels or worse, use inheritance to generate complex hierarchies. And in order to try and keep all that clean, they use design patterns and what not to achieve “compile time checking”, “testability” and a few other mirages of “good code”. Maybe I like leaning over the edge a bit, but I really can’t understand why something that is to be a data carrier has to be part of something that’s as complex (if not more) than a trivial application’s domain. Here are some of the drawbacks of strongly typing all viewmodel data:
1171 viewsIntroducing SeleniuMspec
Happy new year to you all. And to celebrate, I’ve just published my first codeplex project. SeleniuMspec is a template that you can use to generate MSpec BDD tests from Selenium IDE. I’ve been using both Selenium and MSpec for a while now and thought this might save a few seconds when writing some integration tests.
5709 viewsASP.NET MVC 3 CTP1 View Improvements
ASP.NET MVC 3 CTP1 has introduced many improvements, not least of which is in the View. This screencast explores the improvements in the View, specially looking at the awesome new ViewEngine – Razor. It covers Razor syntax, layouts, templates, issues with namespaces etc. It also looks at the new dynamic viewmodel and shows how it can be used to clean up view code. It's just over 45 minutes long and we do go into a little depth. Hope you enjoy it :)
5262 viewsSelecting ListView Items with CheckBoxes
Often we need to enable users to select multiple items from a ListView control and do a batch operation on them. While the ListView control does enable selection, it only supports selecting one row (item) at a time. This article shows a nice, easy and reusable way to enable multiple selection with checkboxes.
6739 viewsASP.NET Routing with IIS 7 – Remember Your Modules
ASP.NET 4.0 introduces routing and it works very well. With IIS 7, there are some interesting configuration options that can help improve your site's performance. When done wrong, they can have unexpected side effects. And we're going to look at one of them today.
7482 viewsASP.NET MVC – Unit Testing JsonResult Returning Anonymous Types
Unit testing of ASP.NET MVC JsonResults can be a source of confusion. The problem arises from the fact that an Action Method itself doesn't produce any html / json / string output – it simply returns an Action Result. ASP.NET MVC then calls the ExecuteResult() method on that Action Result. The ExecuteResult() method is what causes output to be written to the Response stream. Let's take the following controller and action method for example:
1294 viewsFetching a Property Value via Reflection
Reflection is a method by which we can use metadata at runtime to dynamically create an instance of a type, bind the type to an existing object, or get the type from an existing object and invoke its methods or access its fields and properties. It has many uses, ranging from allowing usage of attributes to creating instances of dynamically generated classes and using them. You can even use reflection to read and modify private member variables of an object. Today, we're going to look at a very simple example which will allow us to read the value of a public property given an instance.
3394 viewsASP.NET MVC: ModelBinding Multiple File Uploads to an Array
Web apps often need to upload files. ModelBinding a file upload to an HttpPostedFileBase action parameter is straightforward as long as you know the exact name of the file upload html control. There may be some situations where there are quite a few file upload controls and for whatever reason, they have very different names (they could be autogenerated on the page for example). In such a case, it becomes difficult to know what names to give to the action parameters at compile time. The usual option would be to hook into the Request parameters. That works, but is not very testable (without a good mocking framework like SharpMock, Moles, TypeMock Isolator etc.). In such situations, we can use a model binder to bind all file uploads to a single upload parameter.
5943 viewsEncrypted Hidden Redux : Let's Get Salty
This article builds on the ideas presented in my earlier article http://www.heartysoft.com/post/2010/02/25/Encrypted-Hidden-Inputs-in-ASPNET-MVC.aspx
3279 viewsMVC 2 RC 2 Templated Helper Bug and a Potential Solution
ASP.NET MVC 2 introduces templated helpers. They're a convenient and type safe way to render model data. There is a potential problem in the way in which the system processes the lambda expression passed in to the helper. The problem causes overridden properties to be ignored and uses the base class' declaration of the property instead. This can have adverse reactions where the client side validation feature of ASP.NET MVC 2 is used.
8710 viewsEncrypted Hidden Inputs in ASP.NET MVC
There are many situations where we need to persist some data during the user's session. There are a few options in achieving this:
7072 viewsExposing a WCF Service for Ajax and Silverlight
One of the most attractive features of WCF is that you get to write a service once and expose it to be used by multiple clients using different technologies and protocols. How a WCF service is exposed can be changed simply by changing the configuration file, without needing to recompile the code. In this article, we're going to create a WCF service and expose it to Ajax. We'll test the Ajax service by calling it from ASP.NET Ajax 4.0 and jQuery. We'll then expose the service to Silverlight through binary encoding, which will increase data transfer efficiency. Finally, we'll create a small Silverlight 3.0 application that will call the service.
680 viewsAsp.net MVC 2.0 RC 2 Just Released
I was just moderating the asp.net forums and approved Phil's announcement 29 minutes ago that Asp.net MVC 2.0 RC 2 has just been released:
4262 viewsAjax, Asp.net Ajax, jQuery – Misconceptions and Facts
There seems to be some confusion among a lot of developers about Asp.net Ajax. This article will hopefully clear some doubts regarding what it is, what it isn’t and where jQuery comes in.
629 viewsWoohoo…I’m an Asp.net MVP…and a few questions for you
I was announced asp.net MVP today. It’s great to receive the award as a recognition of my activities at the asp.net forums. I hope I can continue to help people out there and that this site will grow in the process. It’s my first time receiving the award and hopefully it won’t be the last. In an attempt to hold on to it(!), I’ll ask you guys…what should I write about? What aspects of asp.net do you want me to cover? I’ll be posting some video tutorials soon. What topics do you want me to go through? Lemme know and I just might listen ;).
3853 viewsSimple Username / Password Authentication WITHOUT Membership Providers
The Membership provider in asp.net is great. As is the Roles support. You can do some very nifty things with it with a considerable amount of ease. You can get hashed or encrypted passwords and a whole host of features that’s pretty much enterprise grade. And you get it for free. Well, not free, but it is pretty easy to set up.
1229 viewsDisplay Modes of Validator Controls
By default, asp.net validators are positioned right next to the control they validate. You can move them in the markup, but wherever you put them, they occupy an area equal to the area required to display the Text property (or if the Text is not present, then the ErrorMessage property). We may not want that. We may want them to only occupy space when they’re displayed, or not display them at all (and showing the error message in a validation summary only). The validators have a property called display, which can be set to one of three values: Static, Dynamic and None. Setting it to Static will mean the validator will occupy space even when there’s no error. Dynamic means that it won’t occupy space when there isn’t an error, but will show up when there is. None means that the validator’s Text (or ErrorMessage) isn’t displayed at all and doesn’t occupy any space. In this case, you’ll need to use a ValidationSummary control to be able to display the ErrorMessage.