页面加载时的C#数据集到Html列表 [英] C# Dataset to Html List on pageload
问题描述
我在一年前创建了ac#mvc app,我有一个名称和图片的数据集,我的应用程序在页面加载时为列表中的每个人创建一个新的li。
I created a c# mvc app over a year ago where I had a dataset of names and pictures and my app creating a new li for every person on the list when the page loaded.
<ul id="People-List">
@foreach (var people in Model)
{
<li class="resize">
<span>@Person.Name</span>
<br />
<br />
<img alt="Image"src="/@Person.PicturePath" /></a>
<br />
</li>
}
</ul>
我想在C#webforms中使用我的东西做类似的东西想象一下是C#和javascript。
我一直在努力用Javascript添加新的列表项目,我可以做一些关于最佳方法的建议,该程序将加载一个本地数据库的人,将它们放入数据集然后通过数据到前端,它们被添加到上面代码的javascript版本中,根据其中的数据创建html列表。
我最初写的这个代码,但我想知道我是否正确的方式,因为我想在每个列表项中添加按钮和一些变量
I want to make something similar in C# webforms using what I imagine would be C# and javascript.
I have been struggling to add new list items with Javascript and I could do with some advise on the best way to do this, the program would load a local database of people, put them into a dataset then pass the data to the front end where they get added to a javascript version of the code above, creating the html list depending on the data inside it.
I originally wrote this code, but I want to know if im doing it the right way since i will want to add buttons and a number of variables inside each of the list items
<ul id="nav" >
<script type="text/javascript">
a = new Array("pub 1", "pub 2", "pub 3");
for (var i = 0; i < a.length; i++)
{
document.write("<li>" + a[i] + "</li> ");
}
</script>
</ul>
建议?
Advice?
推荐答案
如果您遇到绑定问题,请尝试
KnockoutJS
http://learn.knockoutjs.com/#/?tutorial=collections [ ^ ]
If you have having trouble with binding try
KnockoutJS
http://learn.knockoutjs.com/#/?tutorial=collections[^]
这篇关于页面加载时的C#数据集到Html列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!