后台逻辑层代码方法:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BLL (模型命名空间)
namespace namespace1(自己随意取得一个名字)
{
public class TicketProvider
{
eBuulYinYeTripEntities db = new eBuulYinYeTripEntities();
public string[] GetFromLocatijon()
{
string[] p = (from a in db.表名 select a.字段名).Distinct().ToArray(); //获取所有要查询的字段的值并对字段去重
return p;
}
}
前台遍历:
<select id="" name="">
<option value="请选择">请选择</option>
@foreach (var item in new BLL.TicketProvider().GetFromLocatijon())
{
if (@ViewBag.FromLocatijon == item)
{
<option value="@item" selected="selected">@item</option>continue;
}
<option value="@item">@item</option>
}
</select>