使用html结构输出sql
问题描述:
有没有办法将HTML结构存储在SQL视图中,并通过控制器将其输出到存储的HTML结构中?使用html结构输出sql
例如,这里是希望我通过控制器集成在一个SQL视图,并输出到存储样本HTML
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<IEnumerable<vwStudent>>" %>
<html>
<body>
<table>
<tr>
<th>
Student ID
</th>
<th>
Name
</th>
<th>
GPA
</th>
<th>
Scholarship Amount
</th>
<th>
Eligible Date
</th>
<th>
Is Senior
</th>
</tr>
<% foreach (var item in Model) { %>
<tr>
<td>
<%= Html.Encode(item.StudentID) %>
</td>
<td>
<%= Html.Encode(item.FName) %>
</td>
<td>
<%= Html.Encode(item.GPA) %>
</td>
<td>
<%= Html.Encode(String.Format("{0:F}", item.ScholarshipAmount)) %>
</td>
<td>
<%= Html.Encode(String.Format("{0:g}", item.EligibleDate)) %>
</td>
<td>
<%= Convert.ToString(item.IsSenior) == "True" ? "Yes" : Convert.ToString(item.IsSenior) == "False" ? "No" : null%>
</td>
</tr>
<% } %>
</table>
</body>
</html>
控制器动作:
public ActionResult Students()
{
ViewData.Model = students.vwStudent.ToList();
return View();
}
为什么要将HTML存储在sql表中?您应该将数据和html分开保存在应用程序中 - 从字面上看,整个过程就是使用MVC! – Milney
您将数据(即StudentId等字段)存储在数据库中,然后您的视图(来自asp.net mvc的cshtml文件)将其呈现为HTML格式。 – Milney
@Milney我正试图解决性能问题,数据库查询在10秒内执行,而HTML视图需要5分钟以上才能输出。我正在尝试使视图输出更快 – user793468