0
votes

i've a table name Info. i want to create a partial view of this table of a strongly typed. my partial view in View/Shared is _InfoView.cshtl like:

 @model IEnumerable<RealTest.Models.ifo>

  <h2>_InfoView</h2>

 <p>
 @Html.ActionLink("Create New", "Create")
 </p>
  <table>
      <tr>
         <th>
           name
       </th>
      <th>
         address
       </th>
       <th></th>
    </tr>

 @foreach (var item in Model) {
<tr>
    <td>
        @Html.DisplayFor(modelItem => item.name)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.address)
    </td>
    <td>
        @Html.ActionLink("Edit", "Edit", new { id=item.id }) |
        @Html.ActionLink("Details", "Details", new { id=item.id }) |
        @Html.ActionLink("Delete", "Delete", new { id=item.id })
    </td>
   </tr>
 }

my View page is like: @model IEnumerable

 @{
  ViewBag.Title = "Index";
}
 <p>
   @Html.ActionLink("Create New", "Create")
  </p>

   @Html.Partial("_InfoView")

now i want to call it from another strongly typed view. when i called it it seems that it didn't get required data for partial view.now how i should pass partial view data???

2

2 Answers

0
votes
@{Html.RenderPartial("is _InfoView", model);}

where your model would need to be a collection of ifo objects.

0
votes

You can call it like this

@Html.Partial("ProdItemColors",Model.PropertyName)

For example, If you have a ViewModel called Customer which has a Collection property of type Info like this

public class Customer
{
  public string CustomerName { set;get;}
  public IList<Info> InfoItems { set;get;}

  public Customer()
  {
      InfoItems=new List<Info>();
  }
}
public class Info()
{
  public string Name { set;get;}
}

Now from your main view which is bounded to your Customer class, you can call it like this

@model Customer
<p>@Model.CustomerName </p>
@Html.Partial("_InfoView",Model.InfoItems)

Assuming you have a View called _InfoView.cshtml either in the ~/Views/Shared folder or ~/Views/YourcontrollerName folder.

Make sure your Partial view is bounded to Info class

@model IEnumerable<Info>
<p>do something inside this</p>