Click here to Skip to main content
13,097,225 members (65,696 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I Want to keep search in application can any one help me Here is my code

 public ActionResult Search()
            List<book> bk = new List<book>();
            string query = "select * from Book where StatusTypeId=1";
            SqlCommand cmd = new SqlCommand(query, con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            cmd.CommandType = CommandType.Text;
            DataSet ds = new DataSet();
            foreach (DataRow dr in ds.Tables[0].Rows)
                bk.Add(new Book()
                    BookId = Convert.ToInt32(dr[0].ToString()),
                    Name = dr[1].ToString(),
                    Author = dr[2].ToString()
            return View(bk);
        public ActionResult Search(string Name, Book bk)
            var genlist = new List<book>();
            string query = "select Name from Book where StatusTypeId=1 and Name=" + Name;
            BookDB db = new BookDB();
            ViewBag.Name = new SelectList(genlist);
            SqlCommand cmd = new SqlCommand(query, con);
            var name = from n in db.bookDb
                       select n;
            if (!string.IsNullOrEmpty(Name))
                name = name.Where(n => n.Name.Contains(Name));
            cmd.CommandType = CommandType.Text;
            return RedirectToAction("Index");

View :
    ViewBag.Title = "Serach";
@model IEnumerable<>
@*<form action ="@Url.Action()" method="post">
    input type="button" value="Search" 
                @Html.DisplayNameFor(model => model.Name)
                @Html.DisplayNameFor(model => model.Author)
        @foreach (var item in Model)
                    @Html.DisplayFor(modelItem => item.Name)
                    @Html.DisplayFor(modelItem => item.Author)
                    @Html.ActionLink("Edit", "Edit1", new { id = item.BookId }) |
                    @Html.ActionLink("View", "View", new { id = item.BookId }) |
                    @Html.ActionLink("Delete", "Delete", new { id = item.BookId })
Posted 22-Apr-13 19:04pm
Sorry, this is not a question.
Tadit Dash 23-Apr-13 3:32am
What exactly is the problem ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 23 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100