日期:2014-05-18  浏览次数:20540 次

在线等!如何用MVC3实现会员列表的搜索功能?
我在后台已经实现了会员列表功能,代码如下:
C# code

@model IEnumerable<taomei.Models.Members.MemberInfo>
@{
    ViewBag.Title = "会员信息列表";
}
<h2>
    会员信息列表</h2>
<p>
    @Html.ActionLink("添加会员", "Create")
</p>
<table>
    <tr>
        <td>用户名</td>
        <td>
            <input id="txtUserName" type="text" />
        </td>
        <td>注册时间</td>
        <td>
            
        </td>
    </tr>
</table>
<table style="width: 800px; text-align: center;">
    <tr>
        <th>
            用户名
        </th>
        <th>
            姓名
        </th>
        <th>
            区域
        </th>
        <th>
            地址
        </th>
        <th>
            电话
        </th>
        <th>
            状态
        </th>
        <th>
        </th>
    </tr>
    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.MembUserName)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.MembName)
            </td>
            <td>
                @item.MembRegion.ProvinceName @item.MembRegion.CityName @item.MembRegion.DistrictName
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.MembAddr)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.MembPhone)
            </td>
            <td>
                @(item.MembStatus == 1 ? "有效" : "无效")
            </td>
            <td>
                @Html.ActionLink("修改", "ModifyInfo", new { id = item.MemberId })
                @Html.ActionLink("详情", "Detials", new { id = item.MemberId })
            </td>
        </tr>
    }
</table>



现在我想实现会员搜索功能,不知道怎么写。前台这个页面不知道怎么写,写在什么地方,Controller更不知道怎么写了,盼高手回复!!!在线等!

------解决方案--------------------
HTML code

查询:<input type="text" name="keyword" value="@ViewBag.keyword">

------解决方案--------------------
C# code

if (!string.IsNullOrEmpty(AccountName))
            {
                query = query.Where(lc => lc.AccountName.Contains(AccountName));
            }
            if (!string.IsNullOrEmpty(LCAgentName))
            {
                query = query.Where(lc => lc.LCAgentName.Contains(LCAgentName));
            }
            if (!string.IsNullOrEmpty(ServerIB))
            {
                query = query.Where(lc => lc.ServerIB.Contains(ServerIB));
            }
            if (!string.IsNullOrEmpty(IAM))
            {
                query = query.Where(lc => lc.IAM.Contains(IAM));
            }