Inline HTML Helper at Advanced Level
Example1: Simple Example of Inline HTML Helper
Controller Action
public ActionResult InlineHTMLHelper() { return View(); }
View:
<ul> @helper mylist(string[] arr) { foreach (string data in arr) { <li>@data</li> } } </ul> @mylist(new string[] { "Yogesh","Vikas","Harsh" })
Example 2:
Step1: Create a folder(CustomClasses) and Employee Class
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace testCode.CustomClasses { public class Employee { public int empid; public string empname; } }
Step2: Action
public ActionResult InlineHTMLHelper() { return View(); }
Step 3: View
@using testCode.CustomClasses <ul> @helper mylist1(List<Employee> arr) { foreach (Employee data in arr) { <li>@data.empid</li> <li>@data.empname</li> } } </ul> @mylist1(new List<Employee> { new Employee { empid = 1, empname = "Yogesh" }, new Employee { empid = 2, empname = "Vikas" } })