I’ve created a new C# asp.net mvc 4.0 (beta) Internet Application and I’m having a somewhat odd behavior in the Add View dialog in Visual Studio 2010 (sp1). When I decide to create a strongly-typed View, inside the Add View dialog, the Model class dropdown does not show my ViewModel class.
For the record, yes I did compile the application before triggering the Add View dialog.
I believe I have pinpointed the issue but do not know how to fix it. Below are the repro-steps if anyone cares to reproduce the behavior:
It appears that as soon as I create a class that implements the IAutofacRegistration
interface and build the application, I’m no longer capable of viewing my ViewModels in that dropdown.
Can anyone confirm if they are getting the same results as me? And more importantly, how can one fix this?
IMPORTANT: I have tried the exact same steps with an mvc 3.0 application and the exact same behavior occurs…so this is not relevant to the BETA version.
Sincerely Vince
Go to solution explorer => Views Folder => Right-click on “Model” Folder >> go to “Add” >> Click on [Class] as follow. Provide the required name like “Product. cs” then click on “Add” button as follow.
When you click the submit button, the HttpPost action method above will be executed and the value of model. FavoriteColor will be what you select in the dropdownlist. After that you can use that value to update your database. and you can get the person id in model.
In Solution Explorer, right-click the Controllers folder and then click Add, then Controller. In the Add Scaffold dialog box, click MVC 5 Controller with views, using Entity Framework, and then click Add. Select Movie (MvcMovie. Models) for the Model class.
If you get error message: "Running transformation: The input file appears to be using a schema version not supported by this template. This may lead to compile errors. Please use 'Add New Generated Item' to add an updated template".
You are used EF 5.x. You have to add metadata for EF 5.x to your T4 template. In file header call DefineMetadata()
<#@ template language="C#" debug="false" hostspecific="true"#> <#@ import namespace="System.Text.RegularExpressions" #> <#@ include file="EF.Utility.CS.ttinclude"#><#@ output extension=".cs"#><# DefineMetadata();
at the bottom of your template create method
private void DefineMetadata() { TemplateMetadata[MetadataConstants.TT_TEMPLATE_NAME] = "CSharpDbContext.Types"; TemplateMetadata[MetadataConstants.TT_TEMPLATE_VERSION] = "5.0"; TemplateMetadata[MetadataConstants.TT_MINIMUM_ENTITY_FRAMEWORK_VERSION] = "5.0"; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With