Created
October 7, 2017 03:46
-
-
Save DavidRogersDev/4e9725ecc55fc72bdaaac1c147a22b4e to your computer and use it in GitHub Desktop.
Extension method CreateViewDataDictionary to create a new ViewDataDictionary in ASP.NET Core
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static ViewDataDictionary<T> CreateViewDataDictionary<T>(this HttpContext httpContext, T model) | |
{ | |
var modelMetadataProvider = httpContext.ApplicationServices.GetRequiredService<IModelMetadataProvider>(); | |
return new ViewDataDictionary<T>(modelMetadataProvider, new ModelStateDictionary()) | |
{ | |
Model = model | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment