2014-03-02 42 views
1

我正在返回一个局部视图,但局部视图不显示在我的特定页面部分。我正在返回一个模型。任何人都可以在我的代码中看到问题吗?作为结果,我只获得了局部视图。如何在我的主页CartManager上嵌入_CartListing部分视图?用模型c#返回部分视图mvc4

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="[email protected]"/> 
</td> 
</tr> 
} 

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

Html.Partial( “pathto部分。”) – Casey

回答

2

在你CartManager视图,而不是:

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

尝试

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

没有变化,只有局部视图越来越 – user3300195

+0

不好意思啊试图代替的RenderAction。 – shenku

+0

你能回答这个http://stackoverflow.com/questions/22124432/multiple-ajax-beginform-not-working-c-sharp-mvc – user3300195