0

我有一堂课:

public class ShoppingCartVM
{
   public JsonResult CartRelatedItems { get; set; }
}

还有一个回归的模型

return new JsonResult
{
   Data = listItem,
   JsonRequestBehavior = JsonRequestBehavior.AllowGet, 
};

在控制器中,我将值分配给对象ShoppingCartVMShoppingCartVM属性。

  public ActionResult Index()
  {
     var _relatedItem = qm.GetRelatedItemCart((
                                  HttpContext.User.Identity.IsAuthenticated ?
                                  qm.GetCustomer(HttpContext.User.Identity.Name).PriceLevel.Value : 0
                               ));
     ShoppingCartVM scvm = new ShoppingCartVM()
     {
         CartRelatedItems = _relatedItem
     }
     return View(scvm);
  }

谁能告诉我,如何CartRelatedItems在我的 asp.net mvc 项目的视图中循环属性以通过 ajax 显示。

非常感谢。

4

1 回答 1

0

You can use Partial or RenderPartial for ajax calls using Razor. For example

@Html.Partial("mypartialview") 

or

<% Html.RenderPartial("mypartialview"); %>

Following link could help for detailed on Partial or RenderPartial.

http://www.compiledthoughts.com/2011/01/aspnet-mvc-razor-partial-views-with.html

于 2012-11-14T07:30:14.550 回答