【问题标题】:Return Partial view with model c# mvc4使用模型 c# mvc4 返回部分视图
【发布时间】:2014-04-03 04:02:21
【问题描述】:

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

    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>

【问题讨论】:

  • Html.Partial("部分路径。")

标签: c# asp.net-mvc asp.net-mvc-4 asp.net-ajax


【解决方案1】:

在您的 CartManager 视图中,而不是:

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

试试

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2023-04-01
  • 1970-01-01
  • 2012-10-04
  • 1970-01-01
  • 2020-06-30
  • 1970-01-01
  • 1970-01-01
  • 2013-05-17
相关资源
最近更新 更多