0

PartialView をレンダリングしようとすると、いくつかの問題が発生しました。

私のコントローラー:

public ActionResult Index()
    {
        var db = new fanganielloEntities();
        List<imovel> imoveis = (from s in db.imovel
                                where s.StatusImovel == 3
                                select s).ToList();

        return PartialView(imoveis);
    }

     public ActionResult Listar()
     {
         return View();
     }

景色:

 @Html.Partial("TesteLista")

パーシャル:

@model List Mvc4Web.Models.imovel
    @if (Model != null)
    {
foreach (var item in Model)
{
            @Html.DisplayFor(modelItem => item.DescricaoImovel)
 }
    }

エラー:

オブジェクト参照がオブジェクト インスタンスに設定されていません。

ソース エラー:

5 行目: 6 行目: 7 行目: @foreach (モデルの var item) 8 行目: { 9 行目:

よろしくお願いします!!!

4

2 に答える 2

3

Model を部分ビューに渡す必要があります

あなたの見解で

 @model List<Mvc4Web.Models.imovel>
@Html.Partial("TesteLista",Model)
于 2012-10-11T12:04:16.067 に答える
0

Html.Partialコントローラーアクションを起動しません。TesteLista がレンダリングされたときに Index アクションを起動したい場合は、

@Html.Action("TesteLista") 

代わりは。

于 2012-10-11T12:19:03.043 に答える