MVC display moves if there is a scrollbar.

Use this in the _layouts view to prevent the annoying left twitch if the content is longed than can fit on the display. The scrollbar moved the display to the left unless you put this in the _layouts View.

       /* prevent layout shifting and hide horizontal scroll */
        html {
            width: 100vw;
        }

        body {
            overflow-x: hidden;
        }

I can't use email as Username with MVC5 Microsoft.AspNet.Identity

Problem:

I want to use email (or a dot in the username!) as the username with Microsoft.AspNet.Identity in MVC 5 application. But when I do I get the following error:

User name ... is invalid, can only contain letters or digits.

Solution:

In the AccountController constructor that takes a userManager as a parameter add the following code:

UserManager.UserValidator = new UserValidator<ApplicationUser>(UserManager)
 { AllowOnlyAlphanumericUserNames = false };

Error When renaming ASP.NET MVC 5 applciation

I had this issue a few times already, so I will write down the procedure I follow also as a reminder for myself:

  1. Replace all of the old solution name with the new one.
  2. Navigate to Properties under each project and change the Assembly Name and Default Namespace fields to new solution name.
  3. Go to solution folder and rename all project folders with the new solution name.
  4. Remove all files under bin and obj folders.
  5. Solution will not be able to load projects. Remove all projects and add them again.
  6. Re-build the project.

Source: http://stackoverflow.com/questions/21701297/error-when-renaming-asp-net-mvc-5-applciation

MVC3 deploy - Could not load file or assembly 'System.Web.WebPages.Razor

Whilst deploying my newly upgraded ASP.NET MVC 3 web application to the production environment I started receiving a FileNotFoundException with the error message "Could not load file or assembly 'System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified." I have encountered this before so I know it is about bin-deploying that assembly. But where is the System.Web.WebPages.Razor assembly?

Since you have installed ASP.NET MVC 3 on your development machine you have all these MVC 3 assemblies installed in your GAC. Your production machine does not!

So you need to find this file and make it bin deployable however this cheeky assembly isn't in you solution so how can you do that? Well... add it. Go to Add Reference on your root web project (e.g. Web.csproj) and find System.Web.WebPages.Razor and add.

 

Now right click this assembly in your references directory and click properties.

Now you can make it bin deployable by setting Copy Local to true like so:

Note this is how to deploy the System.Web.WebPages.Razor assembly withe your ASP.NET MVC 3 web application. To deploy a typical setup of an ASP.NET MVC 3 app you will need to do the same for all of the following assemblies:

  • System.Web.Mvc
  • System.Web.Helpers
  • System.Web.Razor
  • System.Web.WebPages
  • System.Web.WebPages.Deployment
  • System.Web.WebPages.Razor as detailed above
  • Microsoft.Web.Infrastructure this will also need a reference added as above
  • WebMatrix.Data this also needs the reference


Of course you only need to add the reference to these assemblies if they are not already there - in most cases it will be. This was mainly a blog post for the slightly more complicated System.Web.WebPages.Razor.dll

Update

There is an easier way to do this if you are using Visual Studio 2010 Service Pack 1 and using Web Deploy as your publish action when publishing. You can add deployable dependencies to your ASP.NET MVC project that will choose the necessary assemblies for you. Even easier!