2011-12-15 25 views
1

これはなぜ動作しないのですか?ViewBagの値を設定しようとしています

エラーNo overload for method 'Write' takes 0 argumentsが表示されます。これは、私がViewBag.InvoiceTotalを設定しているforeachの最初の行で発生します。

@foreach (var invoice in Model.Invoices) 
{ 
    @{ ViewBag.InvoiceTotal = (invoice.Product.Price * invoice.Quantity).ToString("c"); } 

    <tr> 
     <td> 
      @Html.DisplayFor(modelItem => invoice.InvoiceDate) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => invoice.Company.Name) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => invoice.Product.Name) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => invoice.Quantity) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => invoice.Product.Price) 
     </td> 
     <td> 
      @ViewBag.InvoiceTotal 
     </td> 
     <td> 
      @Html.ActionLink("Edit", "Edit", new { id = invoice.InvoiceId }) | 
      @Html.ActionLink("Details", "Details", new { id = invoice.InvoiceId }) | 
      @Html.ActionLink("Delete", "Delete", new { id = invoice.InvoiceId }) 
     </td> 
    </tr> 
} 

答えて

1

あなたは

@foreach (var invoice in Model.Invoices) 
{ 
    { 
    ViewBag.InvoiceTotal = (invoice.Product.Price * invoice.Quantity).ToString("c"); 
    } 
} 

この作品@余分なものを持っています。

+0

驚くばかりです。ありがとう! –

0
 @foreach (var invoice in Model.Invoices) 
      { 
       ViewBag.InvoiceTotal = (invoice.Product.Price * invoice.Quantity).ToString("c"); 

       <tr> 
        <td> 
         @Html.DisplayFor(modelItem => invoice.InvoiceDate) 
        </td> 
        <td> 
         @Html.DisplayFor(modelItem => invoice.Company.Name) 
        </td> 
        <td> 
         @Html.DisplayFor(modelItem => invoice.Product.Name) 
        </td> 
        <td> 
         @Html.DisplayFor(modelItem => invoice.Quantity) 
        </td> 
        <td> 
         @Html.DisplayFor(modelItem => invoice.Product.Price) 
        </td> 
        <td> 
         @ViewBag.InvoiceTotal 
        </td> 
        <td> 
         @Html.ActionLink("Edit", "Edit", new { id = invoice.InvoiceId }) | 
         @Html.ActionLink("Details", "Details", new { id = invoice.InvoiceId }) | 
         @Html.ActionLink("Delete", "Delete", new { id = invoice.InvoiceId }) 
        </td> 
       </tr> 
      } 
関連する問題