首页 / C# / 剃刀语法/ WebMatrix-C#问题
剃刀语法/ WebMatrix-C#问题
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了剃刀语法/ WebMatrix-C#问题,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1220字,纯文字阅读大概需要2分钟。
内容图文
在Windows窗体中,我可以使用以下代码创建一个名为“ Authentication.cs”的类文件:
public class Authentication
{
public string Name;
internal bool Authenticate()
{
bool i = false;
if (Name == "Jason")
{
i = true;
}
return i;
}
}
在WebMatrix中,我可以插入一个名为“ Authentication.cs”的新类文件,并插入上面的代码.
在我的default.cshtml文件中,执行以下操作:
<body>
@{
Authentication auth = new Authentication();
if(auth.Authenticated("jasonp"))
{
<p>@auth.Authenticated("jasonp");</p>
}
}
</body>
但这是行不通的!它适用于WinForms桌面应用程序,但不适用于WebMatrix.我不知道为什么它不起作用.错误消息是:
“The namespace Authenticate does not
exist. Are you sure you have
referenced assemblies etc?”
因此,然后在default.cshtml文件的顶部尝试了此操作:
@using Authentication.cs;
导致完全相同的错误!
在任何地方都找不到任何文档可以告诉您如何在WebMatrix页面中“包含”类文件.
感谢您的帮助,
谢谢!
解决方法:
只需将CS文件放入您的App_Code目录中
然后做这样的事情
@{
Authentication auth = new Authentication();
if(auth.Authenticated("jasonp"))
{
<p>@auth.Authenticated("jasonp");</p>
}
}
无需添加使用.
另外,如果您想使用.dll,则需要使用
@using NameSpace.Authenication
@{
Authenticated auth = new Authenicated();
}
@if(@auth.Authenticated("jasonp"))
{
<p>@auth.Authenticated("jasonp")</p>
}
内容总结
以上是互联网集市为您收集整理的剃刀语法/ WebMatrix-C#问题全部内容,希望文章能够帮你解决剃刀语法/ WebMatrix-C#问题所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。