public ActionResult Search() { List<book> bk = new List<book>(); con.Open(); 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(); da.Fill(ds); 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() }); } cmd.ExecuteNonQuery(); return View(bk); } [HttpPost] public ActionResult Search(string Name, Book bk) { con.Open(); 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; cmd.ExecuteNonQuery(); return RedirectToAction("Index"); }
@{ ViewBag.Title = "Serach"; } @model IEnumerable<demo.mvc.models.book> <h2> </h2> @*<form action ="@Url.Action()" method="post"> </form>*@ @Html.ValidationSummary(true) @Html.BeginForm() <p> Name:@Html.TextBox("Name") Author:@Html.TextBox("Index") input type="button" value="Search" <fieldset> <table> <tr> <th> @Html.DisplayNameFor(model => model.Name) </th> <td> @Html.DisplayNameFor(model => model.Author) </td> </tr> @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.Name) </td> <td> @Html.DisplayFor(modelItem => item.Author) </td> <td> @Html.ActionLink("Edit", "Edit1", new { id = item.BookId }) | @Html.ActionLink("View", "View", new { id = item.BookId }) | @Html.ActionLink("Delete", "Delete", new { id = item.BookId }) </td> </tr> } </table> </fieldset>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)