Safely Encoding Strings On ASP.NET MVC Razor Pages (sometimes)

  Background Sometimes, we want to let html tags come through our web pages from user defined content.  If for example, you have a workflow that requires approval before publishing, there are times when you want to let the author put through html, links, etc.  Solution In Visual Studio write a simple HtmlHelper method that allows for a flag you can pass through.  In my case, I have a database table with a boolean column “allowhtml”.  If this is set, then instead of using Html.Raw(…) I can use my own helper method, pass in the allowHtml value and if it is set true, then allow the not encoded Html to flow through. Here is that helper method: namespace WebAPI.Code.Helpers { public static class … Continue Reading

Simple DropDownList With Default Value Using ASP.NET MVC4, Razor and an HtmlHelper

First, the results of what you get.  Notice the URL parameter, the default value in the DropDownList and also the text value output on the page.   Visual Studio Project Project.zip Background I know a lot of us are struggling changing from ASP.NET WebForms to MVC4.  For me in particular, it’s been a struggle but I’m slowly seeing light at the end of the tunnel.  Our Silicon Valley Code Camp has been in the process of rewriting in MVC4 for the past many months, and with the help of contractors (and me), we are getting there.  Basically, the site has gone from: to The example I’m showing here is really based on just implementing a tag cloud manager. You can see an example of this in production and in … Continue Reading

ImageResizer, Amazon’s CloudFront and ASP.NET’s MVC4 Razor Helper Methods

  Well, the title is certainly a mouthful and hopefully a honey trap for SEO.  The thing is, I’m really going to talk about all those things.  I just went through a short exercise that I thought would be useful to share. Background For Silicon Valley Code Camp, I use the toolkit ImageResizer written by  Nathanael Jones.  For those of you that deal with any quantity of images on their web sites, I strongly recommend taking a look at this.  Before I used this toolkit I written my own image handlers that did some similar things but not nearly as well or with so many features.  One of the issues we have on code camp is that we try and show lots of pictures all the time.  Sponsors and speakers are … Continue Reading

Follow

Get every new post delivered to your Inbox

Join other followers: