I want to print my table in the infinite category system to my cshtml screen with tagbuilder. writes some of it. some of it is not written. please help me.
c# codes:
public IActionResult Index()
{
var tb = new TagBuilder("ul");
using (SqlDbContext vt = new SqlDbContext())
{
var Kategori = from i in vt.urunKategorileri
where i.urunKategorileriUstId == 0
select i;
foreach (urunKategorileri anamenu in Kategori)
{
tb.InnerHtml.AppendHtml("<li><a href='#'>" + anamenu.urunKategorileriKategoriAdi + "</a>"+ Altkategori(anamenu.urunKategorileriId) + "</li>");
}
}
return View(tb);
}
private TagBuilder Altkategori(int id)
{
TagBuilder eb = new TagBuilder("ul");
using (SqlDbContext a = new SqlDbContext())
{
var say = (from i in a.urunKategorileri
where i.urunKategorileriUstId == id
select i).Count();
if (say > 0)
{
TagBuilder ab = new TagBuilder("<ul>");
var altKat = from i in a.urunKategorileri
where i.urunKategorileriUstId == id
select i;
foreach (urunKategorileri altkategori in altKat)
{
ab.InnerHtml.AppendHtml("<li><a href='#'>" + altkategori.urunKategorileriKategoriAdi + "</a>"+ Altkategori(altkategori.urunKategorileriId)+ "</li>");
}
return ab;
}
}
return eb;
}
cshtml codes:
@model TagBuilder
@{
ViewData["Title"] = "Home Page";
}
@Model
screenshot:
console output:
In the console, the sub-categories should normally be listed in the section that says "Microsoft.AspNetCore.Mvc.Rendering.TagBuilder" inside the li tag. but it's not working.
You need to convert
TagBuilder.InnerHtml
to string,if you want to append it to html: