强类型模型/需要模型格式的输出
实际上我是这项技术的新手,我正在使用 mvc2 架构。我无法从我的模型加载数据来查看页面。我使用强类型模型EventListing.Models.EventInfo。我需要模型格式的输出。我如何使用我的选择功能
模型
public class EventInfo
{
public int OPR { get; set; }
public int EVENT_ID { get; set; }
public string SUBSITE { get; set; }
public static DataTable Select()
{
DataTable myDataTable = new DataTable();
Dbhelper DbHelper = new Dbhelper();
DbCommand cmd = DbHelper.GetSqlStringCommond("SELECT * FROM WS_EVENTINFO");
myDataTable.Load(DbHelper.ExecuteReader(cmd));
return myDataTable;
}
控制器
public ActionResult List()
{
return View(EventModel.EventList());
}
视图
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<EventListing.Models.EventInfo>" %>
<% foreach (var model in EventListing.Models.EventModel.EventList())
{ %>
<tr>
<td>
<%= Html.ActionLink(model.TITLE, "Detail", new { id = model.EVENT_ID })%>
actually i'm new to this technology, i am using mvc2 architecture. l cant able to load the data from my model to view page. i used strongly typed model EventListing.Models.EventInfo. i need output in model format. how can i use my select function
Model
public class EventInfo
{
public int OPR { get; set; }
public int EVENT_ID { get; set; }
public string SUBSITE { get; set; }
public static DataTable Select()
{
DataTable myDataTable = new DataTable();
Dbhelper DbHelper = new Dbhelper();
DbCommand cmd = DbHelper.GetSqlStringCommond("SELECT * FROM WS_EVENTINFO");
myDataTable.Load(DbHelper.ExecuteReader(cmd));
return myDataTable;
}
Controller
public ActionResult List()
{
return View(EventModel.EventList());
}
View
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<EventListing.Models.EventInfo>" %>
<% foreach (var model in EventListing.Models.EventModel.EventList())
{ %>
<tr>
<td>
<%= Html.ActionLink(model.TITLE, "Detail", new { id = model.EVENT_ID })%>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
让我尝试稍微清理一下您的代码:
然后在控制器操作中:
最后在视图中:
对此应该做的下一个改进是将数据访问(选择静态方法)外部化到一个单独的存储库中,并具有控制器使用此存储库而不是直接调用 Select 方法来查询数据库。
Let me try to clean up your code a little:
then in the controller action:
and finally in the view:
The next improvement that should be done to this is to externalize the data access (the Select static method) into a separate repository and have the controller use this repository instead of directly invoking the Select method to query the database.