问题一:
我已经开始学习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);
}
}
}
然后我将 Custom HtmlHelper 的命名空间添加到Web.Config
,像这样
<namespaces>
<!--other namespaces-->
<add namespace="MvcTestz"/>
<!--other namespaces-->
</namespaces>
So that I could use intellisense in the razor View ,but it custom Helper didnt showed up in one View (Home/View/About.cshtml)
.
所以从另一个角度来看(Home/View/Index.cshtml)
我添加了命名空间@using MvcTestz;
陈述。
问题二:
WebApp 执行主页时(Home/View/Index.cshtml)
显示输入按钮文本而不将其渲染为 HTML。
On the About page (Home/View/About.cshtml)
sever generates error. (Click for Enlarged) https://i.stack.imgur.com/4vJJw.jpg
Update:
- 智能感知问题已解决,我必须编辑视图目录中存在的 Web.Config。解决了。
-
HtmlString
如果我想渲染一个 Html 按钮,应该使用它。解决了。