asp.net-mvc - VB.NET 中 ViewDataDictionary 实例后的 "!"符号是什么?

标签 asp.net-mvc vb.net

我使用 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 single String 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/

相关文章:

c# - 减少 C# 或 VB.NET 枚举中的值

javascript - Jquery 自动完成链式请求

c# - Json序列化错误 "There is already an open DataReader associated with this Command"

c# - ASP.NET MVC/.NET 的 to_json (rails ) 类似功能

c# - ASP.NET AjaxActionLink 请求中存在潜在危险的 Request.Path

c# - 从多个线程访问 word 文档的单词列表

c# - HTML 条函数

c# - 将委托(delegate)从 C# 转换为 VB.NET

c# - 如何动态添加 HTML 元素 (ASP.NET)

c# - 如何在 ASP.NET MVC 中发布 List<T> 并使模型正常工作?