Note: Visual Studio 2017 - v15.4.1
I'm currently following a basic course on MVC and created a controller with Index, Create, Delete etc. When I right click on the Create method and select "Add View" a window opens. I select the following options:
View Name: Create
Template: Create
Model: PersonModel
When I click the "Add" button I get the following error:
"Error HRESULT E_FAIL has been returned from a call to a COM component"
I've searched high and low to solve this and tried several things I found via the search, but none of them worked, but this morning I tried the same add view steps but with a different model and it worked.
So I compared the two simple models and worked out what was wrong with my "PersonModel" that was causing the issue:
In my "PersonModel" I have the below line:
public string FullName => $"{FirstName} {LastName}";
However, if I change this line to the old style:
public string FullName
{
get { return $"{FirstName} {LastName}"; }
}
the scaffolding works - it looks like the scaffolding doesn't like Expression Bodies. I've tested it by adding in expression bodies to some of the classes that don't have it and it fails on the scaffolding because of it.
Has anyone else found this issue, and is there a way to solve it without changing my class property back to the old way (I prefer the look of the new version and my code formatting tool formats the code to expression bodies).
Thanks