新手请教MVC下ViewData绑定数据问题

yaotomo yaotomo 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
后台查到的数据是Linq多表查询得到的,所以没有对应的Model。


var stus = from t1 in context.Student
join t2 in context.Teacher on t1.teacherid equals t2.id
join t3 in context.Class on t1.gradeid + t1.classid equals t3.gradeid + t3.classid
select new
{
stuid = t1.id,
stuname = t1.name,
stugender = t1.gender,
stuage = t1.age,
stubirthday = t1.birthday,
stuaddress = t1.address,
stuidentity = t1.identityid,
stumobile = t1.mobile,
teaname = t2.name,
t3.classdesc
};
var result = (from s in stus where s.stuid == stuid select s).FirstOrDefault();
//ViewData["stuinfo"] = result;
ViewBag.stuinfo = result;


前台绑定的时候,不管用ViewData还是ViewBag,都提示没有stuname属性。因为只有一行数据,所以不用foreach遍历。
刚学MVC,请各位多多指教,小弟感激不尽!


@{dynamic student = ViewBag.stuinfo;}
姓名: <input class="easyui-textbox" name="stuname" value="@student.stuname" data-options="iconCls:'icon-ok'" style="width:200px">
...全文

相关推荐

评论 10
收藏 已收藏
分享
返回顶部
yaotomo
.NET社区 62,271 成员 668,968 内容