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

Collection Form Post Parameters in WebAPI Controller

image.png

There are lots of ways using ASP.NET MVC4 to collection passed in form parameters (POST) to the WebAPI Controller.  I’m not wanting to create a Model, I’m not wanting to get involved with dynamic variables, I just want the values that are posted in.  Say for example, my post looks like the following: To capture both sessionId and trackId, I can have a WebAPI controller in Visual Studio that looks just like this: namespace WebAPI.Api{ public class SessionRpcController : ApiController { [HttpPost] [ActionName("UpdateSessionTrack")] [Authorize(Roles = "admin")] public HttpResponseMessage PostUpdateSessionTrack( FormDataCollection formDataCollection) … Continue Reading

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

image.png

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

Converting ASP.NET WSP (Web Site Projects) to WAP (Web Application Projects) with VS2012

image_thumb.png

  Background There are quite a few articles written on the differences between WSP’s and WAP’s.  In this article, I will not go into the details but just give you some clean mechanics necessary for converting pages using Visual Studio 2012.  Some of those articles are listed below. http://mitchelsellers.com/blogs/2008/01/02/wap-or-wsp-which-to-use-and-why.aspx http://vishaljoshi.blogspot.com/2009/08/web-application-project-vs-web-site.html http://aspnetresources.com/blog/web_site_vs_web_application_project_wap When I was new to Visual Studio, I did choose WSP projects because it seemed easier. Now that I’ve done quite a bit more with ASP.NET, I much prefer WAP projects.  Actually, I hate WSP projects primarily … Continue Reading

Follow

Get every new post delivered to your Inbox

Join other followers: