I created a search function to show the product name. But in my View it show the error at the foreach. I don't understand why it returns Object reference not set to an instance of an object.
Here's the error:
 Here is my Controller:
Here is my Controller:
public ActionResult _searchPartial()
    {
        List<tblProduct> getProduct = new List<tblProduct>();
        getProduct = db.tblProducts.ToList();
        return View("_searchPartial", getProduct);
    }
    [HttpPost]
    public ActionResult _searchPartial(string getProductName)
    {
        List<tblProduct> getProduct = new List<tblProduct>();
        getProduct = db.tblProducts.Where(m => m.ProductName.Contains(getProductName)).ToList();
        return View("_searchPartial", getProduct);
    }
the View:
@model  IEnumerable<JAx_Collections.Models.tblProduct>
<table style="text-align:center";>
        <tr>    
            <th>Product Name</th>
        </tr>
             @foreach (var m in Model)
             {
         <tr>
            <td>@m.ProductName</td>
         </tr>
             }
</table>
The Model:
namespace JAx_Collections.Models
{
    using System;
    using System.Collections.Generic;
    public partial class tblProduct
    {
        public int ProductID { get; set; }
        public int SupplierID { get; set; }
        public int CategoryID { get; set; }
        public string ProductName { get; set; }
        public int UnitPrice { get; set; }
        public int UnitsInStock { get; set; }
        public int UnitOnOrder { get; set; }
        public virtual tblCategory tblCategory { get; set; }
        public virtual tblSupplier tblSupplier { get; set; }
    }
}
 
     
    