How do I properly register AutoFac in a basic MVC5.1 website?

Here’s what I have – feedback welcome! Global.asax.cs: public class MvcApplication : System.Web.HttpApplication { protected void Application_Start() { // Register Inversion of Control dependencies IoCConfig.RegisterDependencies(); // Typical MVC setup // …. } } App_Start folder: public class IoCConfig { /// <summary> /// For more info see /// :https://code.google.com/p/autofac/wiki/MvcIntegration (mvc4 instructions) /// </summary> public static void … Read more

MVC 5.1 Razor DisplayFor not working with Enum DisplayName

Create new folder Views/Shared/DisplayTemplates Add empty Partial View named Enum, to the folder Replace Enum View code with: @model Enum @if (EnumHelper.IsValidForEnumHelper(ViewData.ModelMetadata)) { // Display Enum using same names (from [Display] attributes) as in editors string displayName = null; foreach (SelectListItem item in EnumHelper.GetSelectList(ViewData.ModelMetadata, (Enum)Model)) { if (item.Selected) { displayName = item.Text ?? item.Value; } … Read more

ASP.NET MVC 5 error handling

The best way is using Global.Asax, because you can manage all types of errors (Ajax calls/ all of unexpected Errors). with others you can’t do it. Like this: protected void Application_Error() { HttpContext httpContext = HttpContext.Current; if (httpContext != null) { RequestContext requestContext = ((MvcHandler)httpContext.CurrentHandler).RequestContext; /* When the request is ajax the system can automatically … Read more

Html.EnumDropdownListFor: Showing a default text

Try to change the Index of LicenseTypes start from 1 not 0 like below: public enum LicenseTypes { Trial = 1, Paid = 2 } Then you can use Range attribute to validate the selected license type like below: public class YourViewModel { //Other properties [Range(1,int.MaxValue,ErrorMessage = “Select a correct license”)] public LicenseTypes LicenseTypes { … Read more

How can I fix assembly version conflicts with JSON.NET after updating NuGet package references in a new ASP.NET MVC 5 project?

Here the steps I used to fix the warning: Unload project in VS Edit .csproj file Search for all references to Newtonsoft.Json assembly Found two, one to v6 and one to v5 Replace the reference to v5 with v6 Reload project Build and notice assembly reference failure View References and see that there are now … Read more

The type ‘Expression’ is defined in an assembly that is not referenced

I am not sure if you are still having this issue or not but i was having the same issue as well. I was able to find the solutions here https://stackoverflow.com/questions/6496223/compilation-error-in-net-4-0-web-config-linq-not-found <add assembly=”System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089″/> <add assembly=”System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089″/> <add assembly=”System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089″/> I hope this helps..