C# and .NET

  • Showing Enums in a dropdownlist on our ASP.NET MVC view

    A little while ago I posted a discussion on a method to decorate Enums with attributes to provide some flexibility with how they are displayed. Background This came about in a project I worked on where we wanted to show user friendly names of an enumeration on a Web UI page, but the same Enum was to be serialized to XML using a different set of names. Most articles concentrated on decorating an Enum with one attribute. We needed two, and wanted the ability to set which of those two took precedence in different scenarios. The code Here, I’m showing an implementation on how you could use that functionality to…

  • Posting content from memory stream using HttpWebRequest c#

    So I needed to upload a zipped file that I was creating in memory and send it to an MVC action on my server. I read plenty of examples and perhaps I could have gone down the route of saving the stream to a file on disk and then using the .net WebClient UploadFile method. But I didn’t and so I’ve ended up with a class based off a number of help from various parties including an excellent example at . A very good place to find the specification on what is needed is at . I found this helped alto and explained some of the missing pieces of information…

  • Getting friendly names from an Enum when decorated with multiple attribute

    It came about in MVC project I was working on that we wanted to output friendly names for a large number of enumerations we were working on directly into a selectable dropdown list. We would have an enum on a ViewModel object and that would be automatically put into a combo box with the selected item shown. Because alot of our model was pre-generated and we were getting these models from XML serialisation we ended up with a bunch of Enums defined like so. Enum TestEnum { [System.Xml.Serialization.XmlEnumAttribute("Tested")] Test, AnotherOne } Ideal. We already had the enums created. So we went about creating a helper method that would work with…

  • On my way towards a skinny controller – ASP.NET MVC

    A learning curve My first attempt at writing a programming blog. Excuse the rambling, I’m a blogger work in progress. Being new to the whole MVC programming concept and to be honest web progamming in general the learning curve to get up to speed and produce an enterprise solution has been pretty intense. This year, I took on that challenge and must say, it’s been an enjoyable experience. The new challenges when writing web applications and a RESTful application has meant to some degree a shift in the way I have often written my software. When starting on my MVC project I quickly decided to adopt the MVVC (Model View…