This is a two part piece on working with Interfaces in MVC via the Html.EditorFor helper.
The first part – “Display” just covers one of those things I tried on the off chance, and was rather surprised that it worked right out of the box.
In the second part I’ll have a look at the next step of the process – binding these interfaces back to their models.
For reference, I’m working with MVC4, in VS 2012 For Web. I think this will also work in MVC3 at least.
For a slightly messy user interface I’m working on, I wanted to be able to have a Model that holds a list of classes that implement an interface.
There is a possibility that all the classes might not be the same, and I was concerned that I was going to end up with a messy
switch statement in my View that called the right Partial depending on which class I found in the list, and that this switch might need to be maintained on an on-going basis.
Continue reading EditorFor and Interfaces Pt1 – Display
Using the DevExpress ASPxTreeList control recently I came across the problem of how to only allow one node checkbox to be selected at once.
There are examples on the DevExpress support site of implementing this using server side code and postbacks, however this isn’t so desirable, as incurring a postback for every time a node is clicked is fairly expensive.
I had a look into how to implement this using the ASPxClientTreeList functionality available to deselect nodes when other nodes are selected. The solution I worked out works reasonably well, with one caveat which is covered at the end.
I thought I’d write up a question I posed today on StackOverflow here: Loading a generic type using Assembly.LoadFrom
I had a pre-existing method that I use to get a type based on a full assembly path and a class name. This resides in a
Continue reading Loading Generic Types with Assembly.LoadFrom
As part of a utility I was writing recently I wanted to hook keyboard input. In particular I was interested in global hooks (ie input to any program, not just mine), and I needed to handle complex key inputs, for example
Ctrl-Alt-G, i.e. keys plus modifiers. The usual way to do this is to use
Looking around I quickly found a class over on CodeProject here. The
globalKeyboardHook class deals with the hooking, allows you to specify which keys you are interested in and disregards the rest. The events are raised using the delegate type
KeyEventArgs and has easily referenced properties for each of the modifier keys. So far so good.
However I found that the instance of
KeyEventArgs I was receiving in my event handler never had the modifier properties set to
true. Looking at the code for the class I couldn’t see anything there that would set the properties in the call back function for
Continue reading Determining the state of modifier keys when hooking keyboard input
I just answered a stackoverflow question regarding a common issue when using Crystal Reports as part of a wider application – setting login credentials through code. Its not as straight forward as it really ought to be.
Rather than simply setting the login/server/database details through a single call there are a number of things that are required:
Continue reading Crystal Reports – setting login credentials through code
An easy way to improve the usability of
sp_who2 is to make a database specific version.
The idea is to leverage the information provided by
sp_who2, but provide a filter for a given database name. This is really handy on either production or development SQL servers with large numbers of databases.
Continue reading Filtering sp_who2 by database