簡體   English   中英

使用模型C#MVC4返回部分視圖

[英]Return Partial view with model c# mvc4

我返回的是局部視圖,但是局部視圖沒有顯示在頁面的特定部分。 我正在退貨。 誰能在我的代碼中看到問題? 結果我只得到了部分視圖。 如何將_CartListing部分視圖嵌入到我的主頁CartManager

    public ActionResult CartManager()
    {
        string user = "jaddu";

          FoodContext db = new FoodContext();

          List<CartListing> fd = (from e in db.FoodItems
                                  join o in db.Carts on e.itemid equals o.itemid 
                                  where o.username==user
                                  select new CartListing 
                                  {
                                   ItemId=e.itemid,
                                   CartId=o.cartid,
                                   Itemname =e.itemname,
                                   Amount =o.amount,
                                   Price=(float)(e.price*o.amount),

                               }).ToList();


          CartModel vm = new CartModel { CartListings = fd };

          return PartialView("_CartListing",vm);

CartManager視圖

<div class="mycontainer">

    <div id="mydiv">
      @{Html.Action("CartManager","Cart");}    
    </div>

</div> 

_CartListing部分視圖

@model CartModel
<table width="100%">
    <tr bgcolor="#E4E4E4">
        <th style="padding-left:20px;">
        FoodIem
        </th>
        <th  style="padding-left:20px;">
      Quantity
        </th>
        <th style="padding-left:20px;">
        Price
        </th>
       <th></th>
    </tr>
    @{
        int i = 0;
        string k;
    }
     @foreach (CartListing ct in Model.CartListings)
     {
         i = i + 1;
   using (Ajax.BeginForm("DeleteCart", "Cart", new { cartid = ct.CartId }, new AjaxOptions()
{
    HttpMethod = "Post",
    OnSuccess = "onSuccess",
    UpdateTargetId = "mydiv"
}, new {id="Form"+i }))
{
<tr>
<td style="padding-left:20px;">
@ct.CartId
</td>
<td style="padding-left:20px;" >
@ct.Amount
</td>
<td style="padding-left:20px;">
@ct.Price
</td>

<td>
<input type="submit" value="delete" id="delete_@i"/>
</td>
</tr> 
}

     }
 <tr bgcolor="#E4E4E4"><td></td><td></td><td></td><td></td></tr>
</table>

在您的CartManager視圖中,而不是:

@{Html.Action("CartManager","Cart");}

嘗試

@{Html.RenderAction("CartManager","Cart");}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM