代码之家  ›  专栏  ›  技术社区  ›  LiamGu

为什么这个代码不能在另一个解决方案中工作?

  •  0
  • LiamGu  · 技术社区  · 15 年前

    我的当前解决方案中包含以下代码,返回“值“”无效”错误。下面的代码片段被缩短为只显示问题区域,而不是整个actionresult。

            Dim tComment As New hdComment
    
            tComment.Comment = collection("wmd-input")
            tComment.MadeOn = DateTime.Now
            tComment.UserID = Session("LoggedInUser")
            tComment.CallID = id
    
            If Not tComment.Comment.Trim().Length = 0 Then
                db.hdComments.InsertOnSubmit(tComment)
            End If
    
            db.SubmitChanges()
    
            Return Redirect("/Calls/Details/" & id)
    

    但是,在前一个项目中,我使用了完全相同的代码,甚至视图也是相同的,但它仍然返回上述错误。

    一切都在接受一个值。

    唯一不同的是它是一个不同的项目。

    我对这个有点不知所措。

    有人有什么想法吗?


    编辑 作为参考,这里是整个actionresult。

    '
    ' POST: /Calls/Details/5
    <Authorize()> _
    <AcceptVerbs(HttpVerbs.Post)> _
    <ValidateInput(False)> _
    Function Details(ByVal id As Integer, ByVal collection As FormCollection) As ActionResult
    
        Dim calls As hdCall = callRepository.GetCall(id)
    
        ViewData("MyCallID") = calls.CallID
        ViewData("UserThatLogged") = calls.UserID
    
        ViewData("TimeLogged") = calls.loggedOn.ToLongDateString & " " & calls.loggedOn.ToLongTimeString
        ViewData("Title") = calls.Title
    
        Dim dataContext As New CustomerServiceModelDataContext
        ViewData("Status") = New SelectList(dataContext.hdStatus, "StatusID", "Status", calls.StatusID)
        ViewData("Type") = New SelectList(dataContext.hdCategories, "CategoryID", "Title", calls.CategoryID)
        ViewData("Company") = calls.hdCompany.Company
        ViewData("Priority") = New SelectList(dataContext.hdPriorities, "PriorityID", "Priority", calls.PriorityID)
        ViewData("CallDetails") = calls.CallDetails
        ViewData("Customer") = calls.hdCustomer.CustomerName
        ViewData("CustomerID") = calls.hdCustomer.CustomerID
        ViewData("CustomerCallCount") = callRepository.CountCallsForThisCustomer(calls.hdCustomer.CustomerID).Count()
        ViewData("ContactNumber") = calls.hdCustomer.Telephone
        ViewData("AssignedTo") = New SelectList(dataContext.aspnet_Users, "UserName", "UserName", calls.AssignedTo)
    
    
        Dim callComments = callRepository.GetCallComments(id)
        Dim db As New CustomerServiceModelDataContext
    
        Try
            Dim tComment As New hdComment
    
            tComment.Comment = collection("wmd-input")
            tComment.MadeOn = DateTime.Now
            tComment.UserID = Session("LoggedInUser")
            tComment.CallID = id
    
            If Not tComment.Comment.Trim().Length = 0 Then
                db.hdComments.InsertOnSubmit(tComment)
            End If
    
            'Update any call changes
            Dim tCall = (From c In db.hdCalls _
                         Where c.CallID = id _
                         Select c).SingleOrDefault
    
    
            tCall.updatedOn = DateTime.Now
            tCall.UpdatedBy = Session("LoggedInUser")
            tCall.StatusID = collection("Status")
            tCall.AssignedTo = collection("AssignedTo")
            tCall.CategoryID = collection("Type")
            tCall.PriorityID = collection("Priority")
    
            db.SubmitChanges()
    
            Return Redirect("/Calls/Details/" & id)
    
        Catch ex As Exception
            ModelState.AddModelError("Error", ex)
            Return View(callComments)
        End Try
    
        Return View(callComments)
    End Function
    

    其余的代码可以工作,如果表单上的wmd输入字段为空,那么只有当表单中有内容时才会抛出错误。

    编辑 对此有点更新,此行:

    If Not tComment.Comment.Trim().Length = 0 Then
    

    现在阅读

    If (Not tComment.Comment.Trim().Length = 0) Then
    

    如果wmd输入框中没有任何内容,则页面会更新,但如果有,则返回 The value '' is invalid.

    2 回复  |  直到 15 年前
        1
  •  0
  •   Shiraz Bhaiji    15 年前

    您可能缺少参考资料。或者框架版本不同。

    另外,它是同一个开发机器吗?ASP.NET-MVC是否同时安装在这两个地方?

        2
  •  0
  •   LiamGu    15 年前

    我设法解决了这个问题,问题实际上在于hdcall和hdcomments之间的外键约束。

    我去掉了禁忌症,重新制作了它们,突然间一切都好了。