C# 内联Html Helper
Controller 代码
using System.Web.Mvc; namespace Demo.Controllers { public class HomeController : Controller { public ActionResult Index() { return View(); } public ActionResult About() { ViewBag.Message = "Your application description page."; return View(); } public ActionResult Contact() { ViewBag.Message = "Your contact page."; return View(); } } }
cshtml代码
@using Demo.Models @{ ViewBag.Title = "内联Html Helpers"; } <h2>@ViewBag.Title.</h2> <h3>@ViewBag.Message</h3> @*这是定义*@ @helper ShowMessage(string[] strArr) { <ol> @foreach (var item in strArr) { <li>@item</li> } </ol> } @helper HelloWorld(StudentModel studentModel) { <p>我是 @studentModel.Name,我来自 @studentModel.Address ,我想对世界说:@studentModel.Words</p> } <p>编程语言集合:【 内联Html Helpers 】</p> @*这里是使用*@ @ShowMessage(new string[] { "Java", "C#", "Python"}) @HelloWorld(new StudentModel() { Name = "比特-周兴兴", Address = "我来自贵州省贵阳市花溪区贵州大学", Words = "我爱写代码!" }) @CommonLnlineHelper.WriteCode("幸福摩天轮")
作者:幸福摩天轮
------------------------------------------------
愿今日之努力日后想起还能浅浅一笑,不愿今日之颓废用长长一生去悔恨!
如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!