विशेषताएँ
- मिनी (DLL आकार केवल 20KB) और उपयोग में आसान।
- .NET Standard 2.0/.NET 4.6/.NET 4.5/.NET 4.0 का समर्थन करता है।
- किसी भी थर्ड पार्टी लाइब्रेरी के बिना।
- Anonymous Types, Dapper Dynamic Query, List/Array/Set/Enumerable, DataTable, Dictionary का समर्थन करता है।
इंस्टॉलेशन
आप पैकेज को NuGet से Visual Studio Package Manager या NuGet UI का उपयोग करके इंस्टॉल कर सकते हैं:
PM> install-package HtmlTableHelperया dotnet कमांड लाइन का उपयोग करें:
dotnet add package HtmlTableHelperFiddle डेमो:
प्रारंभ करें
##### List/Array/Set/Enumerable non Key/Value Type का उदाहरण
``C#
using HtmlTableHelper;
..
var sourceData = new[] { new { Name = "ITWeiHan", Age = "25",Gender = "M" } };
var tablehtml = sourceData.ToHtmlTable();
/*
परिणाम:
*/
Name Age Gender ITWeiHan 25 M
C#
using (var cn = "Your Connection")
{
var sourceData = cn.Query(@"select 'ITWeiHan' Name,25 Age,'M' Gender");
var tablehtml = sourceData.ToHtmlTable();
}
##### Dapper उदाहरण
C#
var sourceData = new[] {new Dictionary
##### Dictionary उदाहरण
Custom Table/TR/TD/TH Attributes (Dynamic Type) C# var data = /List/Array/Set/Enumerable../; var html = data.ToHtmlTable( tableAttributes: new { @class = "SomeClass"} //यह डायनामिक टाइप है, सभी attribute का समर्थन करता है ,trAttributes: new { ID = "SomeID" },tdAttributes: new { width = "120 px" },thAttributes: new { @class = "dark-theme" } ); /* परिणाम:
| .. |
|---|
| .. |
##### Attribute Annotation###### 1. Display :
C#
public class ModelClassWithDisplayAttr
{
[TableColumn(DisplayName = "Column1")] //MyProperty1 प्रॉपर्टी thead-td का innertext : "Column1" रेंडर करेगी
public string MyProperty1 { get; set; }
[TableColumn(DisplayName = "Column2")] //MyProperty2 प्रॉपर्टी thead-td का innertext : "Column2" रेंडर करेगी
public string MyProperty2 { get; set; }
}
###### 2. Skip : C#
public class ModelClassWithSkipAttr
{
[TableColumn( Skip = true)]
public string MyProperty1 { get; set; } //MyProperty1 का html रेंडर नहीं होगा
public string MyProperty2 { get; set; }
}
##### HTMLTableBuilder###### HtmlCaption
C#
var soucreData = new []{ new {MyProperty1="test",MyProperty2=123} };
var html = soucreData.CreateBuilder()
.SetCaption("This is Caption", new { id = "CaptionId" })
.ToHtmlTable();
//Result : | MyProperty1 | MyProperty2 |
|---|---|
| test | 123 |
##### HTMLTableSettingConfigurable InnerHtml Encoding (विशेष कारण के बिना ऐसा न करें, क्योंकि XSS Attack का जोखिम है)
C#
var sourceData = new[] { new { Name = "ITWeiHan" } };//Default Encoding var encodinghtml = sourceData.ToHtmlTable(); //Result:
var htmltablesetting = new HTMLTableSetting() { IsHtmlEncodeMode = false }; var notEncodinghtml = sourceData.ToHtmlTable(HTMLTableSetting: htmltablesetting); //Result:
Extension
ASP.NET Core MVC:
एक IHtmlHelperExtension.cs बनाएँC#
using System.Collections.Generic;
using HtmlTableHelper;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Html;public static class IHtmlHelperExtension
{
public static HtmlString ToHtmlTable
public static HtmlString ToHtmlTable
C#
@Html.ToHtmlTable(new[] { new { Name = "ITWeiHan", Age = "25", Gender = "M" } })
/*
Result:
razor.cshtml
*/
Name Age Gender ITWeiHan 25 M
C#
using System.Collections.Generic;
using HtmlTableHelper;
using System.Web;
using System.Web.Mvc;
ASP.NET MVC 5:
एक HtmlHelperExtension.cs बनाएँ
public static class HtmlHelperExtension
{
public static HtmlString ToHtmlTable var html = enums.ToHtmlTable(tableAttributes, trAttributes, tdAttributes, HTMLTableSetting);
return new HtmlString(html);
}
public static HtmlString ToHtmlTable
डेमो
ASP.NET MVC 5 JQuery DataTable डेमो: `C#
using HtmlTableHelper;
//..
public class HomeController : Controller
{
public ActionResult Index()
{
var datas = new[] { new { Name = "ITWeiHan", Age = "25",Gender = "M" } };
ViewBag.Table = datas.ToHtmlTable();
return View();
}
}
C#
@{
Layout = null;
}
AspNetMvcDemo
@Html.Raw(ViewBag.Table)
ASP.NET Core डेमो:
C#
public class Startup
{
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.Run(async (context) =>
{
var sourceData = new[] { new { Name = "ITWeiHan", Age = "25",Gender = "M" } };
var tablehtml = sourceData.ToHtmlTable();
await context.Response.WriteAsync(tablehtml);
});
}
}
---
Tranlated By Open Ai Tx | Last indexed: 2025-06-30
---