Local function compiler error in ASP.NET web application in VS2017

I recently downloaded VS2017 and tried some of the new C # 7 features. However, I am confused because this does not always work.

Local functions ...

Are they supposed to work in an MVC web application? I created a completely new WPF Desktop application and it works, but when I create a new MVC web application, the following code does not work (yes, I know, this is pointless).

public ActionResult Index() { void TestMethod(string message) { Console.WriteLine(message); } TestMethod("Why isn't this working?"); return View(); } 

The error is not displayed in the IDE, but when I compile it, it gives a list of errors:

 HomeController.cs(13,13,13,17): error CS1547: Keyword 'void' cannot be used in this context HomeController.cs(13,28,13,43): error CS1528: Expected; or = (cannot specify constructor arguments in declaration) HomeController.cs(13,28,13,29): error CS1003: Syntax error, '[' expected HomeController.cs(13,29,13,35): error CS1525: Invalid expression term 'string' HomeController.cs(13,36,13,43): error CS1026: ) expected HomeController.cs(13,36,13,43): error CS1003: Syntax error, ',' expected HomeController.cs(13,43,13,44): error CS1003: Syntax error, ']' expected HomeController.cs(13,43,13,44): error CS1002: ; expected HomeController.cs(13,43,13,44): error CS1513: } expected ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

Am I doing something wrong?

+7
c # asp.net-mvc visual-studio-2017
source share

No one has answered this question yet.

See similar questions:

52
Enabling C # 7 in an asp.net application
23
Inline variable declaration does not compile
thirteen
Using C # 7 functions inside a view in an ASP.NET MVC Core project

or similar:

481
Compile Views in ASP.NET MVC
392
WCF vs ASP.NET Web API
372
How to protect ASP.NET web API
191
Failed to load file or assembly "System.Web.Mvc"
129
ASP.NET 5 MVC: Unable to Connect to IIS Express Web Server
3
TeamCity C # compilation error: invalid term expression 'int'
2
ASP.NET expression expression structures cause build failures
one
Error adding forest controller in asp.net core 1.1 using VS2017
0
How can I debug this ASP.net MVC 4 error in temporary files?
0
IIS with ASP.NET Core compiled with VS2017 not working

All Articles