看看这样传值对不对 一会对一会错 太诡异

R_zhanche 2010-05-29 06:56:54


后台
public News news = new News();
public Class Cclass = new Class();



protected void InitPageInfo()
{
//int NewsId = 40;
int NewsId =Int32.Parse(Request["id"].ToString());
if (Int32.Parse(Request["id"].ToString()) > 0)
news = NewsManage.GetNewsById(NewsId);
this.Title = news.SNews_title;
ChanelId = news.NNews_classId;
Cclass = FirstClassManage.GetFirstClassInfoById(ChanelId);//you wenit

}

前台

<%=news.NNews_content%>
...全文
143 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
米娜Rose 2010-05-30
  • 打赏
  • 举报
回复
调试走几遍
R_zhanche 2010-05-30
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 chenkuikk 的回复:]
int id = int.Parse(request.querystring("id")).tostring()
是不是这样啊
[/Quote]
这个没有问题吧
chenkuikk 2010-05-30
  • 打赏
  • 举报
回复
int id = int.Parse(request.querystring("id")).tostring()
是不是这样啊
R_zhanche 2010-05-30
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 vip__888 的回复:]
两个News类
分别在不同的命名空间下。
你调用的时候 没提示吗?
[/Quote]

我是想用一个呢 为什么会出现2个?
R_zhanche 2010-05-30
  • 打赏
  • 举报
回复



<%=news().NNews_content%>


R_zhanche 2010-05-30
  • 打赏
  • 举报
回复

完整版
protected void Page_Load(object sender, EventArgs e)
{
try
{

if (!IsPostBack)
{
if (Request["id"] != null)
{


news();
}
}


}
catch (Exception ex)
{

Server.Transfer("Index.aspx");
}
}
public News news()

{
News ne = new News();

if(!string.IsNullOrEmpty(Request["id"].ToString()))
{


news=BLL.NewsManage.GetNewsById(NewsId);

return ne;
}

}



前台



<%=news.NNews_content%>




这样的代码是不是news()产生的 这个实例就不能在前台访问到?
R_zhanche 2010-05-30
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 wuyq11 的回复:]
Model.News news =null;
news = NewsManage.GetNewsById(NewsId);
[/Quote]

关键是我要在前台访问这个类库 你这样的话还能访问么?
wuyq11 2010-05-30
  • 打赏
  • 举报
回复
Model.News news =null;
news = NewsManage.GetNewsById(NewsId);
vip__888 2010-05-29
  • 打赏
  • 举报
回复
两个News类
分别在不同的命名空间下。
你调用的时候 没提示吗?
R_zhanche 2010-05-29
  • 打赏
  • 举报
回复
我的DAL BLL 全部都是静态的 以上问题是不是因为这个?
R_zhanche 2010-05-29
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 net_lover 的回复:]
你有2个News类吧,要加上名称空间,如果2个类可以转换,则采用显示转换
news = (News)NewsManage.GetNewsById(NewsId);
[/Quote]

就是这个错误 我只有一个News类

我想的是 news = NewsManage.GetNewsById(NewsId);

这里的news 就是 News news = new News()的news

接收后台的方法。

为什么这样会认为是两个实体类news?

孟子E章 2010-05-29
  • 打赏
  • 举报
回复
你有2个News类吧,要加上名称空间,如果2个类可以转换,则采用显示转换
news = (News)NewsManage.GetNewsById(NewsId);
R_zhanche 2010-05-29
  • 打赏
  • 举报
回复
错误 7 无法将类型“Models.News”隐式转换为“News” E:\Web\view.aspx.cs 55

但是我觉得声明的始终是实体类里的新闻实体

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧