upgrading from MVC4 to MVC5

Found out what need to be done in Views\Web.config. Just copy & paste these sections over what you have: <configSections> <sectionGroup name=”system.web.webPages.razor” type=”System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35″> <section name=”host” type=”System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35″ requirePermission=”false” /> <section name=”pages” type=”System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35″ requirePermission=”false” /> </sectionGroup> </configSections> <host factoryType=”System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35″ /> <pages … Read more

How to add jQueryUI library in MVC 5 project?

The code you see rendering css and scripts on your _Layout.cshtml page (i.e. @Scripts.Render(“~/bundles/modernizr”)) is called bundling. Check out some info here: http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification So, to add jQueryUI you would do the following: In your Global.asax.cs file you should see a number of registrations: BundleConfig.RegisterBundles(BundleTable.Bundles); This goes to the BundleConfig class which registers any bundles. For … Read more

The model backing the ‘ApplicationDbContext’ context has changed since the database was created

Just in case anyone else stumbles upon this that was doing a database first implementation like me. I made a change by extending the ApplicationUser class, adding a new field to the AspNetUsers table, and then had this error on startup. I was able to resolve this by deleting the record created in the __MigrationHistory … Read more

Seed Entities AND Users, Roles?

I don’t seed from the migration, instead use the context db initializer. My context derives from IdentityDbContext so I use this method to seed users and roles: Call an initializer from ctor: public class ApplicationDbContext : IdentityDbContext<ApplicationUser> { private readonly IHttpContextBaseWrapper _httpContextBaseWrapper; static ApplicationDbContext() { // Set the database intializer which is run once during … Read more

MVC 5 Multiple Models in a Single View

I would say this is good example of using ViewModel here. I would suggest something like – Create ViewModel with the composition of the two classes public class AddWeightModel { [Required] [DataType(DataType.Text)] [Display(Name = “Stone”)] public Nullable<short> Stone { get; set; } [Required] [DataType(DataType.Text)] [Display(Name = “Pound”)] public Nullable<short> Pound { get; set; } } … Read more