我认为我的连接没有问题。但是,当我运行该程序并使用“ http://localhost:1290/bolum/hello”链接打开浏览器时,我只是到达
输出:DKLSAJDKLJALSJDLs Q
。如何使用数据库数据?我的模型,视图,控制器文件在底部。我在此处编写时删除了“使用..”行。
控制器
namespace WebApplication4.Controllers
{
public class BolumController : Controller
{
public ActionResult Hello()
{
var bolum = new Hello() { Ad = "Q" };
Console.WriteLine("success");
MySqlConnection con = new MySqlConnection("server=localhost;database=proje;uid=root;password=123456;");
MySqlDataAdapter da = new MySqlDataAdapter("Select * From hasta_bilgileri", con);
DataSet ds = new DataSet();
try{
con.Open();
}
catch (MySqlException e){
Console.WriteLine(e.Message);
}
finally {
da.Fill(ds, "hasta_bilgileri");
con.Close();
}
return View(bolum);
}
}
}
模型
namespace WebApplication4.Models
{
public class Hello
{
public string Ad { get; set; }
}
}
查看
@model WebApplication4.Models.Hello
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Hello</title>
</head>
<body>
<div>
DKLSAJDKLJALSJDLs
@Model.Ad
</div>
</body>
</html>