由於某種原因,我的Html幫助程序無法識別。ASP.NET MVC 3 Html幫助程序無法識別
@using System.Data.SqlClient
@using System.Data
<!DOCTYPE html>
<html>
<head>
<title>Site Visits</title>
</head>
<body>
<div>
@{
public string GetSiteVisits()
{
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(
"SELECT numVisits FROM tblSiteVisits WHERE IPAddress='" + Request.UserHostAddress + "'",
new SqlConnection("Data Source=*****;Initial Catalog=*****;Persist Security Info=True;User ID=*****;Password=*****;MultipleActiveResultSets=True"));
sda.Fill(dt);
string table = "<table><tr>";
foreach (DataColumn dc in dt.Columns)
{
table += "<th>" + dc.ColumnName + "</th>";
}
table += "</tr>";
foreach (DataRow dr in dt.Rows)
{
table += "<tr>";
foreach (Object o in dr.ItemArray)
{
table += "<td>" + o.ToString() + "</td>";
}
table += "</tr>";
}
table += "</table>";
return table;
}
}
<div>
@Html.Raw(GetSiteVisits())
</div>
</div>
</body>
</html>
有人知道如何解決它嗎?
你爲什麼要在視圖中進行模型的工作? – 48klocs
我只需要修復。 –
爲什麼你使用MVC如果你不打算遵循這種模式? – sellmeadog