【发布时间】:2012-10-08 00:12:44
【问题描述】:
我正在尝试使用 Path(),但它下面有一条蓝线,并说:“局部变量(路径)在声明之前不能被引用。”如何使用 Path()?
Imports System.Globalization
Imports System.IO
Public Class MessageController
Inherits System.Web.Mvc.Controller
<EmployeeAuthorize()>
<HttpPost()>
Function SendReply(ByVal id As Integer, ByVal message As String, ByVal files As IEnumerable(Of HttpPostedFileBase)) As JsonResult
' upload files
For Each i In files
If (i.ContentLength > 0) Then
Dim fileName = path.GetFileName(i.FileName)
Dim path = path.Combine(Server.MapPath("~/App_Data/uploads"), fileName)
i.SaveAs(path)
End If
Next
End Function
End Class
【问题讨论】:
-
我已经尝试过了,但是当我将“P”大写时,它只是将其变为小写并在 Visual Studio 中添加了蓝色下划线。
-
没关系,我是个白痴。我现在看到(我从网站复制了这段代码)它使用“路径”作为保留字的变量名。这就是为什么它不起作用!要修复,我可以将
Dim path重命名为Dim path1。
标签: asp.net-mvc vb.net asp.net-mvc-3