Note that there are some explanatory texts on larger screens.

plurals
  1. POasp.net mvc rendering partial view on-demand
    primarykey
    data
    text
    <p>I'm a newbie to asp.net mvc and I'd like to know if what I do is correct. </p> <p>I want to create a view for searching people. Here's what I have so far:</p> <ul> <li><p>The business model class:</p> <pre><code>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&lt;Telephone&gt; Telephones { get; set; } } </code></pre></li> <li><p>The ViewModel class:</p> <pre><code>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; } } </code></pre></li> <li><p>The partial view :</p> <pre><code>@model IEnumerable&lt;MvcApplication2.Models.SearchPersonViewModel&gt; @foreach (var item in Model) { @Html.DisplayFor(m =&gt; item.Id) @Html.DisplayFor(m =&gt; item.FullName) } </code></pre></li> <li><p>The view from which the partial view is called:</p> <pre><code>@Html.Action("Search", "Person"); </code></pre></li> </ul> <p>*The controller method in the PersonController:</p> <pre><code> [ChildActionOnly] public ActionResult Search() { List&lt;SearchPersonViewModel&gt; model = new List&lt;SearchPersonViewModel&gt;(); model.Add(new SearchPersonViewModel() { FullName = "test", Id = 3 }); return PartialView("_SearchPerson", model); } </code></pre> <p>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 ? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload