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 6885237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:36:33+00:00 2026-05-27T05:36:33+00:00

I am trying to create a search box to look for invoices in database.

  • 0

I am trying to create a search box to look for invoices in database. The code for search box is as below:

@using (Ajax.BeginForm("Search", "Invoice", new AjaxOptions() { HttpMethod = "POST" })) 

{

    <% input id="search-field" name="search" type="text" value="" %/>

    <% input id="search-submit" name="search-submit" type="submit" value=""   %/>

}

public ActionResult Search(FormCollection collection)
{

        if (collection["search-field"] == null)
            return RedirectToAction("Index");
        else
        {
            string id = collection["search-field"].ToString();
            return RedirectToAction("Details", "Invoice", id.Trim());
        }
}

Now the problem is that I receive only null values the controller search action.

I am using MVC3 and .NET framework 4.0

I still can not receive the string value while catching the string in next action:

public ActionResult Details(string id)
{

  if(string.IsNullOrEmpty(id))

  return RedirectToAction("Index"); ==============> Here

  ObjectParameter[] parameters = new ObjectParameter[3];

  parameters[0]= new ObjectParameter("CUSTNMBR", id);
  parameters[1] = new ObjectParameter("StartDate", System.DateTime.Now.Date.AddDays(-90));
  parameters[2] = new ObjectParameter("EndDate", System.DateTime.Now.Date);

  return View(_db.ExecuteFunction<Models.Invoices>("uspGetCustomerInvoices", parameters).ToList<Models.Invoices>());

}

  • 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-27T05:36:34+00:00Added an answer on May 27, 2026 at 5:36 am

    The main issue is that you are searching the FormCollection based on the id of the input elements instead of their name attribute. Try writing your code like this:

    View:

    @using (Ajax.BeginForm("Search", "Invoice", new AjaxOptions() { HttpMethod = "POST" })) 
    
    {
    
        <input id="search-field" name="search" type="text" value="" />
    
        <input id="search-submit" name="search-submit" type="submit" />
    
    }
    

    Action:

    public ActionResult Search(string search)
    {    
        if (string.IsNullOrEmpty(search))
            return RedirectToAction("Index");
        return RedirectToAction("Details", "Invoice", search.Trim());
    }
    

    I modified your action so you no longer need to query the FormCollection

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

Sidebar

Related Questions

I'm trying to create a good match query for an auto-complete search box using
I'm trying to create an autosuggest search box using jQuery UI and I would
I am trying to create a popup for a search box and submit the
I'm trying to create pagination for search results using MySQL and ColdFusion. My intention
I have been trying to create a new google custom search engine, but when
Hi I'm trying to create a search box to search customer by last name
I am trying to create a search bar for website which searches the database
I am trying create a search box which will search datatables. The search box
I'm trying to create a 'search box' that matches users by name. The difficulty
I am trying to create a class that allows search of a database to

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.