2017-06-08 9 views
0

フレンド、部分的にオブジェクトを取得

私は "OtherDatas.cshtml"と呼ばれるビューページがあり、彼女の中にPartialViewをレンダリングする必要があります。だから、これを行うには、私はpartialView内のオブジェクトがnullかどうかを確認する必要があります。そうでない場合は、partialViewが表示されます。 partialViewの内部でオブジェクトを取得するにはどうすればよいですか?ここに私のコードは次のとおりです。

OtherDatas.cshtml:

<div class="table-responsive"> 
     @{ 
      if (//I need to check the object inside){ 
       Html.Partial("~/Views/Outrosdados/Search.cshtml"); 
      } 
      else 
      { 
      <table class="table table-striped"> 
       <tr> 
        <th style="min-width:130px;">Mês</th> 
        <th style="min-width:80px;">Amortização</th> 
        <th style="min-width:100px;">Recebimento do Mês</th> 
        <th style="min-width:100px;">Atraso</th> 
        <th style="min-width:100px;">DAMP3</th> 
       </tr> 
      </table> 
      } 
     } 
    </div> 

PartialView search.htmlの:私は 'foreachの' の中身をチェックする必要があり

@model TB_DADOS_MANUAIS 
@using EixoX.Html; 
@using Gestão.Models; 
@using System.Globalization; 
@{ 
    List<TB_OUTROS_DADOS> od = (List<TB_OUTROS_DADOS>)ViewData["outrosDados"]; 
Bootstrap3Presenter<TB_OUTROS_DADOS> presenter = 
Bootstrap3Presenter<TB_OUTROS_DADOS>.GetInstance("pt-BR"); 
ViewBag.Title = "Outros Dados"; 

}

<table class="table table-striped"> 
    <tr> 
     <th style="min-width:130px;">Mês</th> 
     <th style="min-width:80px;">Amortização</th> 
     <th style="min-width:100px;">Recebimento do Mês</th> 
     <th style="min-width:100px;">Atraso</th> 
     <th style="min-width:100px;">DAMP3</th> 
    </tr> 
    @foreach (TB_OUTROS_DADOS dados in od){ 
     <tr> 
<td>@dados.DT_MES_UTILIZACAO.ToString(CultureInfo.CreateSpecificCulture("pt-BR"))</td> 
    <td><span class="money" />@dados.VL_AMORTIZACAO</td> 
    <td><span class="money" />@dados.VL_RECEBIMENTO_MES</td> 
    <td><span class="money" />@dados.VL_ATRASO</td> 
    <td><span class="money" />@dados.VL_DAMP3</td> 
    </tr> 
    } 
</table> 

私はいくつかの 'TB_OUTROS_DADOS'を 'od'リストの中に持っています。

ありがとうございます!

+0

あなたが部分図にメインページを持っているIfステートメントを追加します。部分的に、オブジェクトが存在するかどうかを確認できます。存在する場合は、部分ビューからデータを返します。それ以外の場合は、メインビューのelseステートメントに現在あるものを返します。 – Simon

答えて

1

このようにすることはできません。 Pass List <>を親ビューにモデルとして渡したり、部分ビューのようにこのリストを宣言してからチェックしてください。もし良い場合は部分ビューに渡してください。このようにして :

@{ 
    List<TB_OUTROS_DADOS> od = (List<TB_OUTROS_DADOS>)ViewData["outrosDados"]; 
    <div class="table-responsive"> 
      @{ 
       if (od.Count > 0){ 
        Html.Partial("~/Views/Outrosdados/Search.cshtml",od); 
       } 
       else 
       { 
       <table class="table table-striped"> 
       <tr> 
        <th style="min-width:130px;">Mês</th> 
        <th style="min-width:80px;">Amortização</th> 
        <th style="min-width:100px;">Recebimento do Mês</th> 
        <th style="min-width:100px;">Atraso</th> 
        <th style="min-width:100px;">DAMP3</th> 
       </tr> 
      </table> 
      } 
     } 
    </div> 

そしてPartialView

@model List<TB_OUTROS_DADOS> 
@using EixoX.Html; 
@using Gestão.Models; 
@using System.Globalization; 
@{ 

Bootstrap3Presenter<TB_OUTROS_DADOS> presenter = 
Bootstrap3Presenter<TB_OUTROS_DADOS>.GetInstance("pt-BR"); 
ViewBag.Title = "Outros Dados"; 
} 

<table class="table table-striped"> 
    <tr> 
     <th style="min-width:130px;">Mês</th> 
     <th style="min-width:80px;">Amortização</th> 
     <th style="min-width:100px;">Recebimento do Mês</th> 
     <th style="min-width:100px;">Atraso</th> 
     <th style="min-width:100px;">DAMP3</th> 
    </tr> 
    @foreach (TB_OUTROS_DADOS dados in Model){ 
     <tr> 
<td>@dados.DT_MES_UTILIZACAO.ToString(CultureInfo.CreateSpecificCulture("pt-BR"))</td> 
    <td><span class="money" />@dados.VL_AMORTIZACAO</td> 
    <td><span class="money" />@dados.VL_RECEBIMENTO_MES</td> 
    <td><span class="money" />@dados.VL_ATRASO</td> 
    <td><span class="money" />@dados.VL_DAMP3</td> 
    </tr> 
    } 
</table> 
+0

ありがとうございます。それは私のために働いた!私は不可能な笑をしようとしていると思う – Csorgo

関連する問題