How to create Select List for Country and States/province in MVC

public static List<SelectListItem> States = new List<SelectListItem>() { new SelectListItem() {Text=”Alabama”, Value=”AL”}, new SelectListItem() { Text=”Alaska”, Value=”AK”}, new SelectListItem() { Text=”Arizona”, Value=”AZ”}, new SelectListItem() { Text=”Arkansas”, Value=”AR”}, new SelectListItem() { Text=”California”, Value=”CA”}, new SelectListItem() { Text=”Colorado”, Value=”CO”}, new SelectListItem() { Text=”Connecticut”, Value=”CT”}, new SelectListItem() { Text=”District of Columbia”, Value=”DC”}, new SelectListItem() { Text=”Delaware”, Value=”DE”}, new … Read more

How do I create a MVC Razor template for DisplayFor()

OK, I found it and it’s actually very simple. In my Views\Shared\DisplayTemplates folder I have Reading.cshtml containing the following: @model System.Int32 <span id=”@ViewData.ModelMetadata.PropertyName”>@Model</span> This renders the correct tag using the name of the property as the id attribute and the value of the property as the contents: <span id=”Reading”>1234</span> In the view file this can … Read more

Warning message in async method saying that it lacks await operators

Am I doing something wrong? Well, you’re not really doing anything asynchronously. Your ReportExcelAsync method is entirely synchronous, as it doesn’t have any await expressions. So GenerateReportExcel will call ReportExcelAsync, which will run synchronously, and then return a completed task. All you’ve done at the moment is add a small amount of overhead for creating … Read more

Routing in Asp.net Mvc 4 and Web Api

You could have a couple of routes: public static class WebApiConfig { public static void Register(HttpConfiguration config) { config.Routes.MapHttpRoute( name: “ApiById”, routeTemplate: “api/{controller}/{id}”, defaults: new { id = RouteParameter.Optional }, constraints: new { id = @”^[0-9]+$” } ); config.Routes.MapHttpRoute( name: “ApiByName”, routeTemplate: “api/{controller}/{action}/{name}”, defaults: null, constraints: new { name = @”^[a-z]+$” } ); config.Routes.MapHttpRoute( name: … Read more

aspnet_compiler finding wrong version of System.Web.WebPages 1.0.0.0 instead of 2.0.0.0

I solved this problem by explicitly referencing the 2.0 assembly in Web.config. I suppose that for some reason, the ASP.NET compiler (in my case when running MvcBuildViews), uses the old 1.0 assembly first, if it is found. <?xml version=”1.0″ encoding=”utf-8″?> <configuration> <!– … –> <system.web> <!– … –> <compilation debug=”true” targetFramework=”4.0″> <assemblies> <add assembly=”System.Web.Mvc, Version=4.0.0.0, … Read more

How to create custom additional fields in UserProfile in MVC4

Elaborating from the answer above The WebSecurity.InitializeDatabaseConnection Method help states that If you want to use a database table that contains user profile information (user names, email addresses, and so on), you specify a connection string and table name that the membership system uses to connect to that information. If you do not want to … Read more

Automatic Migrations for ASP.NET SimpleMembershipProvider

update-database -verbose doesn’t work because your model has been changed after your data table already existed. First, make sure there are no changes to the UserProfile class. Then, run: Add-Migration InitialMigrations -IgnoreChanges This should generate a blank “InitialMigration” file. Now, add any desired changes to the UserProfile class. Once changes are added, run the update … Read more