【发布时间】:2012-08-07 11:29:51
【问题描述】:
问题 1:
我已经开始学习 ASP.NET MVC。我做了一个简单的扩展方法,像这样:
namespace MvcTestz //Project is also named as "MvcTestz"
{
public static class SubmitButtonHelper //extension method.
{
public static string SubmitButton(this HtmlHelper helper,string buttonText)
{
return string.Format("<input type=\"submit\" value=\"{0}\">",buttonText);
}
}
}
然后我将自定义 HtmlHelper 的命名空间添加到 Web.Config 中,就像这样
<namespaces>
<!--other namespaces-->
<add namespace="MvcTestz"/>
<!--other namespaces-->
</namespaces>
这样我就可以在 razor 视图中使用智能感知,但自定义 Helper 没有出现在一个视图中 (Home/View/About.cshtml)。
所以在另一个视图中(Home/View/Index.cshtml) 我通过@using MvcTestz; 语句添加了命名空间。
问题二:
在 WebApp 执行时主页(Home/View/Index.cshtml) 显示输入按钮文本而不将其呈现为 HTML。
在关于页面(Home/View/About.cshtml) 服务器上生成错误。 (Click for Enlarged)
更新:
- Intellisense 问题已解决,我必须编辑视图目录中的 Web.Config。已解决。
-
HtmlString如果我想渲染一个 Html 按钮,应该使用它。已解决。
【问题讨论】:
标签: asp.net asp.net-mvc visual-studio-2010 razor html-helper