I'm a beginner and I want to display menu on the middle like This Website(www.kammadanam.com) and when user clicks on any Category Name or its Sub Category Name I want to display Products related to the clicked category.
i am trying this way but it is not correct please provide valid code
i am struck in my project before 1 week.
please help me friends
What I have tried:
MY TABLE:
<pre>Category:
CategoryId(pk), CategoryName, Description,
SubCategory:
SubCategoryId(pk), SubCategoryName, Description, Icon,CategoryId(fk)
Product:
ProductId(pk), Name, Price, Description, CategoryId(fk), SubCategoryId(fk),
my controller is:
public ActionResult Home()
{
Products obj = new Products();
obj.Showall_Menu_Cate = obj.selectalldata_Menu_Cate();
return View(obj);
}
public JsonResult GetSiteMenu(string id)
{
Sample Productobj = new Sample();
DataTable dt = new DataTable();
List<Sample> PrtList = null;
SqlCommand Cmd = new SqlCommand("select * from SubCategory where CategoryID='" + id + "'", Con);
SqlDataAdapter Da = new SqlDataAdapter(Cmd);
DataSet Ds = new DataSet();
Da.Fill(Ds);
PrtList = new List<Sample>();
for (int i = 0; i < Ds.Tables[0].Rows.Count; i++)
{
Sample CatObj = new Sample();
CatObj.SubCategoryID = Ds.Tables[0].Rows[i]["CategoryID"].ToString();
CatObj.SubCategoryName = Ds.Tables[0].Rows[i]["CategoryName"].ToString();
PrtList.Add(CatObj);
}
return new JsonResult { Data = PrtList };
}
my Model is:
public List<Sample> selectalldata_Menu_Cate()
{
List<Sample> PrtList = null;
SqlCommand Cmd = new SqlCommand("select * from Category", Con);
SqlDataAdapter Da = new SqlDataAdapter(Cmd);
DataSet Ds = new DataSet();
Da.Fill(Ds);
PrtList = new List<Sample>();
for (int i = 0; i < Ds.Tables[0].Rows.Count; i++)
{
Sample CatObj = new Sample();
CatObj.Id = Ds.Tables[0].Rows[i]["Id"].ToString();
CatObj.CategoryID = Ds.Tables[0].Rows[i]["CategoryID"].ToString();
CatObj.CategoryName= Ds.Tables[0].Rows[i]["CategoryName"].ToString();
CatObj.Description = Ds.Tables[0].Rows[i]["Description"].ToString();
CatObj.Image = Ds.Tables[0].Rows[i]["Image"].ToString();
CatObj.CreatedOn = Ds.Tables[0].Rows[i]["CreatedOn"].ToString();
CatObj.Status = Ds.Tables[0].Rows[i]["Status"].ToString();
PrtList.Add(CatObj);
}
return PrtList;
}
View:
@foreach (var item in Model.Showall_Menu_Products)
{
<li class="dropdown">
<a href="@Html.ActionLink(item.ProductName,"Shop", "Kammadanam",new { id="Pandu2" },new { @class= ".button_action"})"></a>
<ul>
@foreach (var item2 in Model.Showall_Menu_Category)
{
<li>
@*@Html.ActionLink("Solar Water heaters", "Shop", "Kammadanam")*@
<a href="@Html.ActionLink(item2.CategoryName,"Shop", "Kammadanam",new { id ="Pandu" },new { @class= ".button_a"})"></a>
</li>
}
@*<li><a href="shop.html">Solar LED Lights</a></li>
<li><a href="shop.html">solar water pumps</a></li>
<li><a href="shop.html">solar potable led & lamp LED</a></li>*@
</ul>
</li>
}
Ajax Method:
<script>
$('.button_action').click(function (index) {
$.ajax({
url: "/Kammadanam/getProduct/",
contentType: 'application/html; charset=utf-8',
type: 'GET',
data: {
id: $("#Pandu2").val()
},
success: function (result) {
debugger
$("#Pandu").attr('href', result)
}
});
return false;
});
</script>