Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 492785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T02:08:53+00:00 2026-05-13T02:08:53+00:00

Good Morning All, I am developing a new ASP.net MVC web application. Part of

  • 0

Good Morning All,

I am developing a new ASP.net MVC web application. Part of it’s functionality is to search the Parts List on the SQL Server database. I have created a ADO.net Entity Data Model as part of the solution and named it PartList. I’m using master pages and want the search control rendered on it. As such, I’ve created PartsForm.ascx in the Shared directory as:

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

I also created a PartsController which serves 2 purposes: 1) to render the entire parts list on the Parts page and 2) to search the parts list and return results to the PartsForm.ascx. Here’s the code for 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

Intended search control functionality: Receive input search string and conduct search on either PartName or NSN depending on which dropdownlist selection is made. I would like to output the search results to a separate page. Can anyone provide me with some help and guidance as to how to resolve this issue and create the intended functionality?

Thanks,

Sid

Clarification: I’m not understanding why I receive the error message Object Reference not Set to Instance of Object on the PartsForm.ascx file. Besides the ADO.net Entity Data Model (edmx file), do I need to create a class to define each of the fields in my model? I’ve seen some of that done in tutorials, but thought that the edmx file took care of that? Is that why this error message is being thrown?

Relevant Code:

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

Snippet from PartsController:

 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

After modifying PartsController and PartsForm.ascx as displayed above, the error message still persists.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T02:08:53+00:00Added an answer on May 13, 2026 at 2:08 am

    Still fairly vague but here is what I’m seeing.

    The page is submitting to itself. not a problem but when you return from your Search controller you are not also returning the PARTNAME or NSN objects.

    That may be because you left that out of your question.

    If not then create another class which has your search result, PARTNAME and NSN objects and return that to the page.

    The use Model.PARTNAME ect and for your products Model.Products or something like that.

    If this is wrong then please provide more relevant code or a small snippet of code that fails.

    EDIT

    Sorry you should return SearchType in your new class back to your view not like I said NSN and PARTNAME

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.