English 中文(简体)
搜索A部分 表 使用ASP.net MVC和ADO.net实体 数据模型给出了“错误目标参考书”,而不是“目标事例”。
原标题:Searching A Parts Table Using ASP.net MVC and ADO.net Entity Data Model gives Error Object Reference not Set to Instance of Object

上午 所有人,

我正在开发一个新的伙伴关系。 MVC网净应用。 其部分功能是检索LQ服务器数据库中的零部件清单。 作为解决办法的一部分,我建立了ADO.net实体数据模型,并将其命名为List。 我使用主页,希望能对其进行搜索控制。 因此,我在共同名录中编造部分:

<%@ 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%>

我也创建了一个部分主计长,其宗旨为: (1) 将所有部分清单放在各部分页和2号上,以查找各部分清单,并将结果归还各部分。 兹在《备件法》中:

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

预定的搜索控制功能: 接收对Name部分或NSN的任何部分进行输入搜索,并根据这些部分进行除名选择。 我希望将搜索结果定在单独的一页。 谁能向我提供某种帮助和指导,说明如何解决这一问题和创造预期功能?

感谢

Sid

查明: 我不理解为什么我收到错误的信息。 除了ADO.net 实体数据模型(dmx文档)外,我是否需要设立一个类别来界定我模型中的每一领域? 我看到了一些在辅导中做的工作,但认为x子档案对此有所关注? 为什么这一错误信息被推翻?

相关法律:

<%@ 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%>

部分 主计长:

 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

在对上面显示的零部件和零件进行修改后,错误信息依然存在。

最佳回答

仍然含糊不清,但这里是我所看到的。

该网页是自备的。 这不是一个问题,而是当你从你的搜捕控制员返回时,你也不会回到国家空间活动局或国家独立党的物体。

这可能是因为你把这个问题留给了你。

否则,就会再造一个有你的搜索结果的班子,即PartNAME和NSN物体,然后返回网页。

使用模式。 PartNAME ect and for You products Model. 产品或类似产品。

如果错了,请提供更相关的法典或一部小型的法典。

http://www.ohchr.org。

如果我不喜欢NSN和NNAME。

问题回答

暂无回答




相关问题
WebForms and ASP.NET MVC co-existence

I am trying to make a WebForms project and ASP.NET MVC per this question. One of the things I ve done to make that happen is that I added a namespaces node to the WebForms web.config: <pages ...

Post back complex object from client side

I m using ASP.NET MVC and Entity Framework. I m going to pass a complex entity to the client side and allow the user to modify it, and post it back to the controller. But I don t know how to do that ...

Create an incremental placeholder in NHaml

What I want to reach is a way to add a script and style placeholder in my master. They will include my initial site.css and jquery.js files. Each haml page or partial can then add their own required ...

asp.net mvc automapper parsing

let s say we have something like this public class Person { public string Name {get; set;} public Country Country {get; set;} } public class PersonViewModel { public Person Person {get; ...

structureMap mocks stub help

I have an BLL that does validation on user input then inserts a parent(PorEO) and then inserts children(PorBoxEO). So there are two calls to the same InsertJCDC. One like this=>InsertJCDC(fakePor)...

ASP.NET MVC: How should it work with subversion?

So, I have an asp.net mvc app that is being worked on by multiple developers in differing capacities. This is our first time working on a mvc app and my first time working with .NET. Our app does not ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

热门标签