I'm a newbie to asp.net mvc and I'd like to know if what I do is correct.
I want to create a view for searching people. Here's what I have so far:
The business model class:
public class Person { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public Address Address { get; set; } public DateTime DOB { get; set; } public List<Telephone> Telephones { get; set; } }
The ViewModel class:
public class SearchPersonViewModel { public int Id { get; set; } public string FullName { get; set; } public string LicencePlate { get; set; } public string CarMake { get; set; } public string CarModel { get; set; } }
The partial view :
@model IEnumerable<MvcApplication2.Models.SearchPersonViewModel> @foreach (var item in Model) { @Html.DisplayFor(m => item.Id) @Html.DisplayFor(m => item.FullName) }
The view from which the partial view is called:
@Html.Action("Search", "Person");
*The controller method in the PersonController:
[ChildActionOnly]
public ActionResult Search()
{
List<SearchPersonViewModel> model = new List<SearchPersonViewModel>();
model.Add(new SearchPersonViewModel() { FullName = "test", Id = 3 });
return PartialView("_SearchPerson", model);
}
Now the problem is that the Search method is called whenever the main View is loaded. What I want is to add a search textbox on the mainview for filtering the collection rendered in the partial view. How could I do that ?