Tag archive for ‘C#’
C# Literal Types
When you are specifying literal numeric values in your code you will, on occasion, have to give the compiler a heads-up on the expected type from the declaration.
For example, the literal value 5.3 will, by default, be assumed to be a double. As such, the following
1
float result = 5.3 / 12.4;
will result in the [...]
RssResult - An ASP.NET MVC RSS ActionResult
One of the most common tasks for data serving websites is offering an RSS feed that users can subscribe to in order to keep up with the latest updates to that data.
Previously I posted the article Creating a simple RSS feed using ASP.NET MVC which demonstrated how to create an RSS feed in a quick, [...]
C# boolean to string extension method
One of the most common operations I find myself repeating when programming is writing a boolean value in a human friendly form. Most users, unless geeky and appreciative of the coolness of datatypes, will not be too comfortable with true/false being used in yes/no context.
I’m a BIG believer in developing my own reusable code [...]
CSS class property in ASP.NET MVC HtmlAttributes
When adding an ActionLink or using a similar Html helper on your C# ASP.NET MVC views you will on occasions want to pass a css class via the htmlAttributes parameter. As this is normally achieved by creating an anonymous type you may expect the following code snippet to work.
1
<%= Html.ActionLink("My Link", "MyLink", null, new { [...]
Creating a simple RSS feed using ASP.NET MVC
Looking to serve an rss document via your ASP.NET MVC controller? Here is a simple, quick means to do so. If you are looking for a much neater, smarter, reusable method of serving rss from your controllers check out my ASP.NET MVC RssResult post (coming soon).
For the demonstrations below I will be using a generic [...]
ASP.NET MVC root url’s with generic routing
Normally, the url to handle a contact view would look similar to /Home/Contact. I’m really not keen on that and wanted my top level view’s url to look like /Contact. This in itself is easy enough, you just create a route {action} and set that routes default controller value to { controller = “Root” }. [...]
JSON serialization in ASP.NET
When working with JavaScript and ASP.NET together you will no doubt find yourself having to return objects from the server side domain to the client side domain.
One common method of doing this is to return XML which represents the object you wish to return. You then map the values in the XML document to [...]
How to consume an XML feed in ASP.NET - RSS
XML is the standard for distributing content on the internet, however it can prove a challenge when trying to consume and handle the data retrieved from an XML document. This is the first in a two part series on consuming and displaying XML content on your own website. We will be using XPathDocument and [...]
Parsing dates when ASP.NET’s DateTime.Parse doesn’t work
Has DateTime.Parse ever thrown the following exception when you passed it a legally formatted value, leaving you bemused as to why it can’t parse it?
String was not recognized as a valid DateTime
As powerful as DateTime.Parse is, it cannot handle every representation of a date/time value without a little help from you, the developer.
External sources [...]
ASP.NET Request.Querystring with escaped ampersands
Take the following url “/images/myimage.jpg&width=300″. URL Encoding has no support whatsoever for HTML Encoding so passing an escaped ampersand html entity though a url in this format is illegal. Now, you may well be thinking “Hold on a minute William, I need to escape my ampersands to have valid XHTML markup on my pages”. Your [...]