问题
I think my connection has no problem. But when I run the program and opened browser with this link "http://localhost:1290/bolum/hello" I reached just
Output: DKLSAJDKLJALSJDLs Q
. How can I use my database data? My model,view,controller files are on the bottom. I removed "using .." lines when writing here.
CONTROLLER
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);
}
}
}
MODEL
namespace WebApplication4.Models
{
public class Hello
{
public string Ad { get; set; }
}
}
VIEW
@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>
来源:https://stackoverflow.com/questions/51099082/how-to-handle-data-thats-coming-from-from-database-in-c-sharp