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

ASP.NET MVC 4 Editor Template for basic types

Editor templates work by convention. The name of the template must match the name of the type. So for example if SomeValue is an int type you could write a custom editor template at ~/Views/Shared/EditorTemplates/Int32.cshtml which will be used. In this case all integer types will use this custom template when you write @Html.EditorFor(model => … Read more

System.ComponentModel.DataAnnotations.compare vs System.Web.Mvc.Compare

So, looking at the MSDN documentation and doing a literal comparison of the two classes, I noticed both classes are derived from System.ComponentModel.DataAnnotations.ValidationAttribute. In fact, the classes are almost exactly the same. The only notable difference is that the MVC version also implements IClientValidatable which adds the following properties: FormatPropertyForClientValidation – (static member) Formats the … Read more

Role based authentication in the new MVC 4 Internet template using simplemembership

Found an answer here by Mehdi Golchin which seems to take care of: [Authorize(Roles=”admin,editor,publisher”)] If I also add this to the home controller: [InitializeSimpleMembership] Because this attribute is on the Accounts controller, SimpleMembership database gets initialize only after the first use of the accounts controller like login/register. Even when the current user gets logged in … Read more

Open mvc view in new window from controller

This cannot be done from within the controller itself, but rather from your View. As I see it, you have two options: Decorate your link with the “_blank” attribute (examples using HTML helper and straight HMTL syntax) @Html.ActionLink(“linkText”, “Action”, new {controller=”Controller”}, new {target=”_blank”}) <a href=”https://stackoverflow.com/questions/14509616/@Url.Action(“Action”, “Controller”)” target=”_blank”>Link Text</a> Use Javascript to open a new window … Read more