Contents tagged with MVC

  • Slow Razor Views in MVC? Make Sure You're Not In Debug Mode

    A short and sweet tip for today - I was investigating a page which I thought had some performance issues. My initial assumption was the backend controller, but a combination of SQL Profiler and Glimpse (which is super great and easy to use) showed me that the real bottleneck was ViewResult.ExecuteResult(). While someone on the internet suggested it might be a bunch of Url.Actions() causing … more

  • Correctly Posting String Data To A WebAPI Controller

    Seems like a pretty simple scenario, right? So I got to work and wrote the following: [HttpPost] [Route("api/users/me/delete")] public HttpResponseMessage CoolMethod(string myData) { } However, when attempting to actually call into the controller, all I was getting back was 404/not found errors. Seems strange, right? The following worked without issue, though: [HttpPost] [Route("api/users/me/ … more

  • MVC Pro-Tip: Anti-Forgery Cookie Token And Form Field Token Do Not Match

    Just a really quick thing for you to check - one of the users of a MVC admin system I administer complained that they were getting this error message, after a release: System.Web.Mvc.HttpAntiForgeryException: The anti-forgery cookie token and form field token do not match. It turns out they hadn't logged out and back in again since the release - as we are hosting the website on Azure, the … more

  • MVC Pro Tip: Rendering A ViewResult As HTML String Output

    Perhaps you've tried this - creating a controller, getting the ViewResult and attempting to convert it to a HTML string (for example, my use case was for an email templating / generation system). It's not terribly difficult, but there are a few caveats - primarily, that when you just "new" up a Controller outside of the proper MVC lifecycle, it doesn't have a proper ControllerContext associated … more

  • MVC Model Binding: Complex Objects and Collections

    Also known as "Why is my ViewModel returning null values to my HttpPost action?" The answer is at the very bottom if you feel like skipping straight to it. Let's say for example you have the following ViewModel and classes: public class MyViewModel { public ComplexObject MyComplexObject { get; set; } public int Value { get; set; } public IEnumerable<ComplexObject> … more

  • Why Is Url Not The Same As RawUrl On My HttpRequest (Adventures in prerender.io)

    Merry Christmas / Happy New Year! Now that the holiday break is unfortunately over, back into the swing of things and good old hard work. Working on implementing prerender.io using the rather old (but does-the-job) MVC HttpModule on GitHub; I got it to a stage where prerender.io was working for the home page but no other pages on the site. A bit of debugging later, I noticed that the Url had … more

  • Pro-Tip: MVC Bundling Gotchas - Minimized Files and Stylesheet Order

    A few quick tips for anyone who's attempting to add scripts or stylesheets via bundling in ASP.NET MVC and wondering why things aren't working. Minified Items Say you have the following in your App_Start\BundleConfig.cs: bundles.Add(new ScriptBundle("~/mybundle/sample").Include( "~/Content/Scripts/modernizr.custom.min.js", "~/Content/Scripts/site.src.js" )); … more

  • Orchard CMS: Planting My First Orchard

    Tried to set up Orchard CMS today, and went a little bit crazy trying to get it to run; even though in the end, none of the problems turned out to be very difficult. First of all, it just kept throwing back 500 Server codes; so to see what's actually going wrong, head into Orchard.Web, edit the Web.config and make sure: in system.WebServer you have <httpErrors errorMode="Detailed"/> (and … more

  • Why Did I Wait This Long To MVC / Razor?

    Started doing work on a small piece of MVC / Razor today, and it's great, really really great - it's just such a nicer model than standard ASP.Net, and you get nice separation of concerns, and having done a bunch of WP7 / MVVM-ish work, it feels...right. One thing I did come across was the need for cascading dropdowns - I ended up using this nice little jQuery plugin, which works as advertised ( … more

  • 1