我使用 Visual Studio 2015 RTM 创建了一个新的 Web 应用程序,并为其选择了 MVC 模板。
它为我创建了一堆代码,其中包括一个名为 AccountController
的 Controller 。包含一个完全像这样的方法:
<AllowAnonymous>
Public Function Login(returnUrl As String) As ActionResult
ViewData!ReturnUrl = returnUrl
Return View()
End Function
什么
!
符号有吗?它是 vb.net 语法的一部分吗?
最佳答案
这是感叹号运算符。请参阅 Special Characters in Code (Visual Basic) 中的“感叹号 (!) 运算符”部分:
Use the
!
operator only on a class or interface as a dictionary access operator. The class or interface must have a default property that accepts a singleString
argument. The identifier immediately following the!
operator becomes the argument value passed to the default property as a string.
所以,而不是做:
ViewData("ReturnUrl") = returnUrl
你可以做:
ViewData!ReturnUrl = returnUrl
关于asp.net-mvc - VB.NET 中 ViewDataDictionary 实例后的 "!"符号是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32383721/