积极答复者
MVC强类型数据怎么赋值?

问题
答案
-
-
你好:)
你的意思是不需要把View继承ViewPage<Model>——即不需要Model的m=>m.Name的形式?而是直接
【示例代码】
1)在某个Controller中,使用SqlDataSource和SqlCommand从数据库中读取指定的内容。
public Action XXXX ()
{
using (SqlConnection con = new SqlConnection("……"))
{
SqlCommand cmd = new SqlCommand("……",con);
string value = cmd.ExecuteScaler().ToString(); //Read the single value (first row, first column)
ViewData["data"] = value;
return View();
}
}
2)页面
<input type="text" …… value='<%=ViewData["data"].ToString()%>'/>
- 已标记为答案 JiyuanModerator 2011年9月1日 1:59
全部回复
-
-
你好:)
你的意思是不需要把View继承ViewPage<Model>——即不需要Model的m=>m.Name的形式?而是直接
【示例代码】
1)在某个Controller中,使用SqlDataSource和SqlCommand从数据库中读取指定的内容。
public Action XXXX ()
{
using (SqlConnection con = new SqlConnection("……"))
{
SqlCommand cmd = new SqlCommand("……",con);
string value = cmd.ExecuteScaler().ToString(); //Read the single value (first row, first column)
ViewData["data"] = value;
return View();
}
}
2)页面
<input type="text" …… value='<%=ViewData["data"].ToString()%>'/>
- 已标记为答案 JiyuanModerator 2011年9月1日 1:59