[英]How to define razor helper for C# MVC project so that namespace is found?
[英]How to define namespace for imported project
我真的很难尝试引用导入到空白项目的项目中的方法/类。 重新创建此文件的确切步骤如下
如果现在构建并运行该项目,则运行正常,没有错误。
5在VS解决方案资源管理器中,对于所有导入的文件,右键单击并选择“包括在项目中”
现在尝试重建项目我得到错误
The type or namespace name 'GetAdminMasterPage' could not be found
(are you missing a using directive or an assembly reference?)
GetAdminMasterPage.cs位于WebApplication1\\App_Code\\class\\GetAdminMasterPage.cs
,看起来像这样
#region using references
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web.Caching;
using System.Web.UI;
#endregion
/// <summary>
/// Gets the MasterPage for the user selected Admin Theme.
/// </summary>
public class GetAdminMasterPage : System.Web.UI.Page
{
#region Get Admin MasterPage
protected override void OnPreInit(EventArgs e)
{
if (Cache["cachedAdminMaster"] == null)
{
GetDefaultMasterPage();
}
else
{
string loadMasterFromCache = Cache["cachedAdminMaster"].ToString();
Page.MasterPageFile = loadMasterFromCache;
}
}
private void GetDefaultMasterPage()
{
try
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbMyCMSConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand("sp_admin_SelectMasterPage", con);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
SqlDataReader myReader = cmd.ExecuteReader(CommandBehavior.SingleResult);
if (myReader.Read())
{
string masterPageFileName = myReader["ThemeUrl"] as string;
Cache.Insert("cachedAdminMaster", masterPageFileName, null, DateTime.Now.AddSeconds(300), System.Web.Caching.Cache.NoSlidingExpiration);
Page.MasterPageFile = masterPageFileName;
}
myReader.Close();
con.Close();
con.Dispose();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
#endregion
}
现在给出错误的一种方法的示例是
using System;
public partial class admin_admin_edit_css : GetAdminMasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
//gives error The type or namespace name 'GetAdminMasterPage' could not be found
(are you missing a using directive or an assembly reference?)
所以我知道我必须Using xxxxxx;
来引用GetAdminMasterPage Using xxxxxx;
但只是找不到正确的语法。
首先,为什么仅当我选择“包含在项目中”而不是仅在复制时才发生错误?
其次,如何使用正确的GetAdminMasterPage路径修复错误?
注意:您不创建新项目。
1.将MYWSAT35文件夹复制到驱动器中(例如:d:\\ MYWSAT35)
2.在Visual Studio中转到文件->打开网站
3.选择d:\\ MYWSAT35并单击打开
4.按F5键运行应用程序
您必须作为网站打开该项目。
如果您使用的是VS2010,它将提示您升级到.net 4.0。 您可以选择不。
但是,如果您在VS2012中打开,它将在没有提示的情况下将其打开。
两者都将成功构建。
在将项目作为网站打开后,右键单击该项目,然后选择“转换为Web应用程序”。 转换的结果是您想要移至空白项目的内容,或者您可能希望将更改保留在原处。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.