English 中文(简体)
不能坐着JSON,就认为是p.net mvc。
原标题:Can not looping JSON result in the view of asp.net mvc

I added the data to the list , and return it as JSON in my controller :

List<ProductListingModels> prom = new List<ProductListingModels>();
ProductListingModels product = new ProductListingModels();

foreach (var item in ien_item)
{
   if ((item.Brand.IsAuthorized == true) && ((HelperClass.ICEContact.PathBrandImages + 
   item.Brand.Image) != null))
   {
     product.BrandImage = HelperClass.CheckImageUrlExist(item.Brand.Image);
   }
   else
   {
     product.BrandImage = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
   }
}

prom.Add(product);
return Json(new
{
   ja = prom.ToList()

}, JsonRequestBehavior.AllowGet);

我认为:

$.getJSON("ProductListing/Index", data, function (product) {
  $.each(data, function (index, proValByDep) {
     alert(proValByDep.BrandImage);
  iii

iii

I traced it in firebug ready, the JSON works well. The problem :

proValByDep.BrandImage is undefined.

任何解决办法请见。 非常感谢。

最佳回答

我认为,你使用<代码><>/代码>在<代码>each()方法中的变量,而不是使用持有所交数据的<编码><产品/编码>参数。

$.getJSON("ProductListing/Index", data, function (product) {

  //   changed data to product below and also added .ja as you want to access its value
  $.each(product.ja, function (index, proValByDep) {
     alert(proValByDep.BrandImage);
  });
});
问题回答

或许需要直接登录在<代码>数据.ja上,因为它是阵容的,而不是直接登录在<代码><>/>上。

$.getJSON("ProductListing/Index", data, function (product) {
  $.each(data.ja, function (index, proValByDep) {
     alert(proValByDep.BrandImage);
  });
});

或者,你可以改变服务器面,直接返回阵列,而不是在名称为<条码>的>>/代码>上加以包装。

return Json(prom, JsonRequestBehavior.AllowGet);




相关问题
WebForms and ASP.NET MVC co-existence

I am trying to make a WebForms project and ASP.NET MVC per this question. One of the things I ve done to make that happen is that I added a namespaces node to the WebForms web.config: <pages ...

Post back complex object from client side

I m using ASP.NET MVC and Entity Framework. I m going to pass a complex entity to the client side and allow the user to modify it, and post it back to the controller. But I don t know how to do that ...

Create an incremental placeholder in NHaml

What I want to reach is a way to add a script and style placeholder in my master. They will include my initial site.css and jquery.js files. Each haml page or partial can then add their own required ...

asp.net mvc automapper parsing

let s say we have something like this public class Person { public string Name {get; set;} public Country Country {get; set;} } public class PersonViewModel { public Person Person {get; ...

structureMap mocks stub help

I have an BLL that does validation on user input then inserts a parent(PorEO) and then inserts children(PorBoxEO). So there are two calls to the same InsertJCDC. One like this=>InsertJCDC(fakePor)...

ASP.NET MVC: How should it work with subversion?

So, I have an asp.net mvc app that is being worked on by multiple developers in differing capacities. This is our first time working on a mvc app and my first time working with .NET. Our app does not ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

热门标签