mirror of
https://github.com/rudollee/LearningMVC.git
synced 2026-08-11 16:32:55 +00:00
Ch. 21 Helper Methods
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace HelperMethods.Infrastructure
|
||||
{
|
||||
public static class CustomHelpers
|
||||
{
|
||||
public static MvcHtmlString ListArrayItems(this HtmlHelper html, string[] list)
|
||||
{
|
||||
TagBuilder tag = new TagBuilder("ul");
|
||||
|
||||
foreach (string str in list)
|
||||
{
|
||||
TagBuilder itemTag = new TagBuilder("li");
|
||||
itemTag.SetInnerText(str);
|
||||
tag.InnerHtml += itemTag.ToString();
|
||||
}
|
||||
|
||||
return new MvcHtmlString(tag.ToString());
|
||||
}
|
||||
|
||||
public static MvcHtmlString DisplayMessage(this HtmlHelper html, string msg)
|
||||
{
|
||||
string encodedMessage = html.Encode(msg);
|
||||
string result = string.Format("This is the message: <p>{0}</p>", encodedMessage);
|
||||
return new MvcHtmlString(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user