如何在视图MVC ASP.net中更改模型主义?

时间:2014-11-18 08:10:49

标签: c# jquery asp.net ajax asp.net-mvc

所以我设法在一个方法上进行AJAX调用:

[HttpPost]
public List<Person> changeFilter()
{
      List<Person> list = new List<Person>();
      list = (from p in db.Persons where p.YearsOfWorkExperience > 5 select p).ToList();
      return list;
}

但我现在不知道如何更改我的视图中的列表?任何人都有任何建议/线索..我认为我做错了什么,但我不确定是什么,我喜欢这方面的一些帮助,因为这对我来说都是新的。我试图在谷歌上查找一些东西,他们使用局部视图只有我的结果页面没有局部视图是问题还是还有其他方法?

我的全部观点:

@model IEnumerable<Smoelenboek.Models.Person>

@{
    ViewBag.Title = "Search Skills";
}


<h2>Search People</h2>

@using (Html.BeginForm("SearchSkills", "Person", FormMethod.Get))
{

    <div class="search">
       @Html.TextBox("parameter")

       <select name="choice" class="choicecheckbox">
          <option id="knowsalready">Knows Already</option>
          <option id="wantstolearn">Wants To Learn</option>
          <option id="hobbies">Hobbies</option>
          <option id="name">Name</option>
       </select>

       <input class="inputsearch" type="submit" value="Search" /> 
    </div>
}
<br />
<h2>Search results</h2>
<div class="searchfilters">
    <br />
    <input id="checkboxlocationfilter" type="checkbox" name="locationFilter" class="locationFiltercss" onchange="changeFilter()">
    <label for="checkboxlocationfilter" class="locationFiltercss">Filter on location</label>
    <br />
    <input id="checkboxlevelofknowledgefilter" type="checkbox" name="levelFilter" class="locationFiltercss">
    <label for="checkboxlevelofknowledgefilter" class="locationFiltercss">Filter on skill level of knowledge</label>    
    <br />
    <input id="checkboxlevelofwantstolearnfilter" type="checkbox" name="levelFilter" class="locationFiltercss">
    <label for="checkboxlevelofwantstolearnfilter" class="locationFiltercss">Filter on skills level of wants to learn</label>
    <br />
    <input id="checkboxpopularityfilter" type="checkbox" name="levelFilter" class="locationFiltercss">
    <label for="checkboxpopularityfilter" class="locationFiltercss">Filter on popularity</label>
    <br />
    <input id="checkboxhobbyprojectsfilter" type="checkbox" name="levelFilter" class="locationFiltercss">
    <label for="checkboxhobbyprojectsfilter" class="locationFiltercss">Filter on only hobbyprojects</label>
    <br />
    <input id="checkbox5yearsfilter" type="checkbox" name="levelFilter" class="locationFiltercss">
    <label for="checkbox5yearsfilter" class="locationFiltercss">Filter on years of work experience more than 5</label>
    <script type="text/javascript">
        $(checkbox5yearsfilter).click(function () {
            if ($(checkbox5yearsfilter).is(':checked')) {
                $.ajax({
                    type: 'POST',
                    url: '../Person/changeFilter',
                    datatype: 'Smoelenboek.Models.Person',
                    success: function (data) {
                        alert(data);
                    },
                    error: function (data) {
                        alert("failed");
                    }
                });

            }
        });
    </script>
    <br />
    <input id="checkbox10yearsfilter" type="checkbox" name="levelFilter" class="locationFiltercss">
    <label for="checkbox10yearsfilter" class="locationFiltercss">Filter on years of work experience more than 10</label>
    <br />
    <input id="checkbox15yearsfilter" type="checkbox" name="levelFilter" class="locationFiltercss">
    <label for="checkbox15yearsfilter" class="locationFiltercss">Filter on years of work experience more than 15</label>
    <br />
    <input id="checkboxphonenrfilter" type="checkbox" name="levelFilter" class="locationFiltercss">
    <label for="checkboxphonenrfilter" class="locationFiltercss">Has phone number</label>
    <br />
    <input id="checkboxextrainfoyfilter" type="checkbox" name="levelFilter" class="locationFiltercss">
    <label for="checkboxextrainfoyfilter" class="locationFiltercss">Has extra info</label>
    <br />
    <input id="checkboxextrainfonfilter" type="checkbox" name="levelFilter" class="locationFiltercss">
    <label for="checkboxextrainfonfilter" class="locationFiltercss">doesn't have extra info</label>
</div>
<div class="searchresults">
    <table>
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.Name)
            </th>
            <th>
                Knowledge
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Email)
            </th>
            <th>
                Skills to learn
            </th>
            <th>
                Project
            </th>
            <th>
                Years of work experience
            </th>
            <th>
                Hobby projects
            </th>
            <th>
                Summary
            </th>
            <th>
                Extra Information
            </th>
        </tr>

    @foreach (var item in Model) {
        <tr>
            <td>
                @Html.ActionLink(item.Name.ToString(), "/SearchSkillsDetails", new { id = item.ID })
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.LearntSkillsAndLevelOfSkills)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Email)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.SkillsToLearn)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Stand)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.YearsOfWorkExperience)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.HobbyProjectICTRelated)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Summary)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.ExtraInfo)
            </td>
        </tr>
    }

    </table>
</div>

0 个答案:

没有答案