【发布时间】:2016-04-14 12:35:42
【问题描述】:
我想用数据库中的某些字段填充视图的某些部分。我不确定如何使这项工作。这是我现在的情况……
这是我的控制器操作:
public ActionResult Course_page(string id)
{
string abbrev = id;
var cpage = from c in db.Course_page
select c;
if (!String.IsNullOrEmpty(abbrev))
{
cpage = cpage.Where(x => x.abbrev.Contains(abbrev));
}
return View(cpage);
}
我的模特:
[Table("course_page")]
public class Course_page
{
[Key]
public int CourseID { get; set; }
public string Meta { get; set; }
public string Title { get; set; }
public string Country { get; set; }
public string main_image { get; set; }
public string list_1 { get; set; }
public string list_2 { get; set; }
public string list_3 { get; set; }
public string list_4 { get; set; }
public string list_5 { get; set; }
public string list_6 { get; set; }
public string list_7 { get; set; }
public string list_8 { get; set; }
public string list_9 { get; set; }
public string list_10 { get; set; }
public string testim_1 { get; set; }
public string testim_2 { get; set; }
public string testim_3 { get; set; }
public string course_site { get; set; }
public string popup_script { get; set; }
public string abbrev { get; set; }
}
视图(缩短):
@model IEnumerable<oltinternational_mvc.Models.Course_page>
<div id="main_container">
<article class="content">
<h1>{@Html.DisplayNameFor(modelItem => cpage.Title)}</h1>
</article>
</div>
我知道我必须在视图的某处引用 cpage 变量,但我不确定以何种方式。这个想法是,课程页面将根据 URL 提供的 ID 加载正确的详细信息。
请有人告诉我如何在视图文件中包含 cpage 变量,或者我是否以正确的方式执行此操作?
【问题讨论】:
标签: c# asp.net-mvc database linq