좋은 아침 모두의 인스턴스로 설정되지 않았습니다 제공는 오류 개체 참조가 개체
나는 새로운 ASP.net MVC 웹 응용 프로그램을 개발하고있다. 그것의 기능 중 하나는 SQL Server 데이터베이스의 Parts List를 검색하는 것입니다. 솔루션의 일부로 ADO.net Entity Data Model을 작성하고 PartList라는 이름을 지정했습니다. 마스터 페이지를 사용하고 검색 컨트롤을 렌더링하고 싶습니다. 1) 파트 페이지에 전체 부품 목록을 렌더링, 2) 검색 :
<%@ Control Language="VB" Inherits="System.Web.Mvc.ViewUserControl(Of DielToolMVC.PartList)" %>
<%=Html.ValidationSummary("Please correct the errors and try again")%>
<% Using (Html.BeginForm())%>
<fieldset>
<p>
<label for="Parts">Please enter a part description or NSN.</label>
<%=Html.DropDownList("PARTNAME",Model.PARTNAME)%>
<%=Html.DropDownList("NSN", Model.NSN)%>
<%=Html.ValidationMessage("Part Name or NSN", "*")%>
</p>
<p>
<input type="submit" value="Search" />
</p>
</fieldset>
<% End Using%>
가 나는 또한이 목적을 제공하는 PartsController을 만든 : 따라서, I는 공유 디렉토리에 PartsForm.ascx을 만들었습니다 부품 목록을 표시하고 결과를 PartsForm.ascx에 반환합니다. 여기 PartsController에 대한 코드는 다음과 같습니다
Public Class PartsController
Inherits System.Web.Mvc.Controller
Private _entities As New Diel_inventoryEntities()
'
' GET: /Parts/
Function Index() As ActionResult
Return View(_entities.PartList.ToList())
End Function
'
' GET: /Parts/Details/5
Function Details(ByVal id As Integer) As ActionResult
Return View()
End Function
'
' GET: /Parts/Create
Function Create() As ActionResult
Return View()
End Function
'
' POST: /Parts/Create
<AcceptVerbs(HttpVerbs.Post)> _
Function Create(ByVal collection As FormCollection) As ActionResult
Try
' TODO: Add insert logic here
Return RedirectToAction("Index")
Catch
Return View()
End Try
End Function
'
' GET: /Parts/Edit/5
Function Edit(ByVal id As Integer) As ActionResult
Return View()
End Function
'
' POST: /Parts/Edit/5
<AcceptVerbs(HttpVerbs.Post)> _
Function Edit(ByVal id As Integer, ByVal collection As FormCollection) As ActionResult
Try
' TODO: Add update logic here
Return RedirectToAction("Index")
Catch
Return View()
End Try
End Function
Function Search(ByVal id As String, ByVal SearchType As String) As ActionResult
If SearchType = "description" Then
Dim SearchResult = From p In _entities.PartList _
Where p.PARTNAME = id _
Select p
Return View(SearchResult)
End If
If SearchType = "NSN" Then
Dim SearchResult = From p In _entities.PartList _
Where p.NSN = id _
Select p
Return View(SearchResult)
End If
Return View("UnknownType")
End Function
End Class
의도 검색 제어 기능 : 입력 검색 문자열을 수신하고 여기서 partName 또는 NSN 중 하나가 DropDownList로 선택하게됩니다에 따라에 검색을 실시하고 있습니다. 검색 결과를 별도의 페이지로 출력하고 싶습니다. 누구든지이 문제를 해결하고 의도 한 기능을 만드는 방법에 대한 도움과 지침을 제게 제공 할 수 있습니까?
감사합니다,
시드
명확한 설명 : 나는 오류 메시지 객체 참조가 PartsForm.ascx 파일에서 개체의 인스턴스로 설정되지 않았습니다받을 이유가 이해하지 못하는거야. ADO.net Entity Data Model (edmx 파일) 외에도 내 모델의 각 필드를 정의하는 클래스를 만들어야합니까? 튜토리얼에서 그 중 일부를 보았지만 edmx 파일이이를 처리했다고 생각 했습니까? 이 오류 메시지가 표시되는 이유는 무엇입니까?
관련 코드 : PartsController에서
<%@ Control Language="VB" Inherits="System.Web.Mvc.ViewUserControl(Of DielToolMVC.PartList)" %>
<%=Html.ValidationSummary("Please correct the errors and try again")%>
<% Using (Html.BeginForm("Search", "PartsController"))%>
<fieldset>
<p>
<label for="Parts">Please enter a part description or NSN.</label>
<%=Html.TextBox("searchtext") %>
<%=Html.DropDownList("PARTNAME",Model.PARTNAME)%>
<%=Html.DropDownList("NSN", Model.NSN)%>
<%=Html.ValidationMessage("Part Name or NSN", "*")%>
</p>
<p>
<input type="submit" value="Search" />
</p>
</fieldset>
<% End Using%>
발췌문 : 위에 표시되는 PartsController 및 PartsForm.ascx을 수정 한 후
Function Search(ByVal id As String, ByVal SearchType As String) As ActionResult
If SearchType = "PARTNAME" Then
Dim SearchResult = From p In _entities.PartList _
Where p.PARTNAME = id _
Select p
Return View(SearchResult)
End If
If SearchType = "NSN" Then
Dim SearchResult = From p In _entities.PartList _
Where p.NSN = id _
Select p
Return View(SearchResult)
End If
Return View("UnknownType")
End Function
Function Result(ByVal id As String, ByVal SearchResult As String) As ActionResult
Return View("SearchResult")
End Function
이 오류 메시지가 계속.
추가하십시오 말했다 좋아하지보기에 다시 새로운 클래스에 searchType이 반환해야 죄송합니다. 귀하의 질문은 막연합니다. – jfar