我正在开发ASP.NET MVC5 SPA。我有一个名为HomeController.cs
的文件,它的视图名为_Home.cshtml
。
我想实现当前逻辑:当用户进入_Home
视图时,应用程序连接到存储库并获取一些数据,然后将视图中的数据填充到<li></li>
元素中。
这是我的HomeController.cs
课程
public class HomeController : Controller
{
public ActionResult Index()
{
//I am not sure if this code should be in Index method
//Assume, that data is taken from repository, but it's no matter
var contactsListModels = new List<ContactListModel>()
{
new ContactListModel() {FirstName = "Fred", LastName = "Perry"},
new ContactListModel() {FirstName = "Jon", LastName = "Skeet"}
};
//In some way need to pass it into _Home.cshtml
return View();
}
}
_Home.css
<div class="col-md-3">
<div class="col-contacts">
<div class="col-contacts-textbox-and-contacts">
<input type="text" class="form-control" />
<!-- Manually added data, but it has to be automatically passed from repository-->
<ul>
<li>Jon Skeet</li>
<li>Fred Perry</li>
</ul>
</div>
</div>
</div>