1
我想創建一個分頁幫助器。它需要的唯一參數是currentpage,pagecount和routename。 但是,我不知道是否可以在我的html助手的定義中使用另一個html助手的返回值。我特指Html.RouteLink。我該怎麼做才能在類定義中做這樣的事情ASP.NET MVC 2中的自定義HTML幫助器
using System;
using System.Web.Mvc;
namespace MvcApplication1.Helpers
{
public static class LabelExtensions
{
public static string Label(this HtmlHelper helper, string routeName, int currentpage, int totalPages)
{
string html = "";
//Stuff I add to html
//I'd like to generate a similar result as the helper bellow.
//This code does not work, it's just an example of what I'm trying to accomplish
html .= Html.RouteLink(pageNo, routeName, new { page = pageNo - 1 });
//Other stuff I do the html
return html;
}
}
}
謝謝。
請問您可以發佈一個上面的代碼樣本,這會讓我更加清楚。謝謝。 – Interfector 2010-06-13 16:00:50
你的代碼或多或少是正確的... html助手基本上是構建插入到頁面標記中的字符串,所以你可以做任何你想做的事情......甚至插入評論和東西,如果你喜歡。 – ckramer 2010-06-13 16:18:23