Hi SUJAYS,
Check this example. Now please take its reference and correct your code.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
Model
public class ProductModel
{
public int Id { get; set; }
public string Name { get; set; }
public decimal? Price { get; set; }
}
Controller
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
return View(GetProducts());
}
[HttpPost]
public ActionResult Index(FormCollection _Collection)
{
string txt = _Collection["searchInput"];
string txt1 = _Collection["PRNO"] == "" ? "0" : _Collection["PRNO"];
IEnumerable<ProductModel> _Product = GetProducts()
.Where(x => x.Name.ToLower() == txt.ToLower() || x.Id == Convert.ToInt32(txt1))
.ToList();
return View(_Product);
}
public IEnumerable<ProductModel> GetProducts()
{
NorthwindEntities entity = new NorthwindEntities();
IEnumerable<ProductModel> _Product = entity.Products
.Select(x => new ProductModel
{
Id = x.ProductID,
Name = x.ProductName,
Price = x.UnitPrice
}).ToList();
return _Product;
}
}
Screenshot