Using C# 6's using static syntax in MVC App_Code display helpers

前端 未结 2 1336
遇见更好的自我
遇见更好的自我 2021-01-24 22:10

Is it possible to use C# 6.0\'s new \"using static\" notation inside of display helpers in App_Code in MVC 5?

I attempted to do so but it did not seem to like the syntax

相关标签:
2条回答
  • 2021-01-24 22:30

    I think I'm using mvc 5 and it's working for me. System.Web.Mvc.dll version 5.2.3.0

    I'm running this in VS 2015 which uses c# 6.0. So it's either that or the version 5.2.3.0 that's doing it.

    So the answer by Kevin it may not be 100% correct.

    MVC 6 is not "stable" in a very broad sense of the word so we are using MVC5 atm.

    Note that at first it didn't find my static reference, but there was no squiggly. After cutting and repasting the "@using static" line a few times it started working. I can navigate to definition on my static extension method.

    0 讨论(0)
  • 2021-01-24 22:36

    This is not possible in MVC5 but MVC6.

    See code change for supporting using static in MVC6: https://github.com/aspnet/Razor/commit/1879ac642754b5f84e6055580e6fc60e13fa2100

    0 讨论(0)
提交回复
热议问题