我正在扩展htmlhelper。但是我不能把它叫做renderaction。
using System.Text;
using System.Web.Mvc;
using System.Web.Mvc.Html;
public static class ViewHelpers
{
public static string Text(this HtmlHelper htmlHelper, string name, object value, bool isEditMode)
{
htmlHelper.RenderAction(...) //cannot be called
}
}如何调用RenderAction?
发布于 2010-02-19 07:08:52
解决方案真的很简单。
添加using Microsoft.Web.Mvc;
在调用RenderAction时,它会将html字符串直接写入视图
发布于 2012-08-29 08:54:54
CoffeeCode在正确的轨道上,但要包括的命名空间应该是System.Web、System.Web.Mvc和System.Web.Mvc.Html.
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Resources;
using System.Web.Routing;
using System.Text.RegularExpressions;
namespace xxx.yyy.Helpers {
public static class HelperView {
public static void RenderHeader(this HtmlHelper helper) {
helper.RenderAction("Header", "Default", new { pageAction = helper.ViewContext.RouteData.Values["action"].ToString() });
}
}
}http://msdn.microsoft.com/en-us/library/ee703490(v=vs.108).aspx
发布于 2010-02-18 07:53:36
@CoffeeCode,你能解释一下为什么要这样做吗?
一般来说,您会调用helper将html作为字符串返回,然后在页面中呈现该字符串。
想要在helper中呈现它似乎有点奇怪。至少对我来说是这样。
编辑
我觉得这里的帮手可能不适合你。如果你想要访问列表,但又不想把它传递给视图,那么帮助器就是错误的地方。您可能想创建一个接受列表的类,对其执行操作,然后返回html。
https://stackoverflow.com/questions/2285344
复制相似问题