asp.net mvc - MVC Razor to produce JSON -


i new mvc , razor. trying hard hands in it.

public actionresult details(int id)         {             var album = storedb.albums.find(id);         //   var albumimages = storedb.albumimages.find(id);             //icollection<albumimages> albumimages = getalbumimages(id);             //viewbag.albumimages = albumimages;             //if (albumimages.count > 0)             //    viewbag.initialimage = albumimages.elementat(0).album800.tostring();              return view(album);         }  on cshtml in javascript need, in prodgallery  in place of "uploads/800/saree800.jpg" need @viewbag.album800  "content/uploads/380/saree380.jpg" need @viewbag.album380  "content/uploads/64/saree64.jpg" need @viewbag.album64 

in short string should dynamically generated viewbag data.

 <script type="text/javascript">     var prodgallery = jqblvg.parsejson('{"prod_1":{"main":{"orig":"../../content/uploads/800/saree800.jpg","main":"../../content/uploads/380/saree380.jpg","thumb":"../../content/uploads/64/saree64.jpg","label":""},"gallery":{"item_0":{"orig":"../../content/uploads/800/saree800.jpg","main":"../../content/uploads/380/saree380.jpg","thumb":"../../content/uploads/64/saree64.jpg","label":""},"item_1":{"orig":"images/0001-1.jpg","main":"images/large/0001-1.jpg","thumb":"images/small/0001-1.jpg","label":""},"item_2":{"orig":"images/0001-5.jpg","main":"images/large/0001-5.jpg","thumb":"images/small/0001-5.jpg","label":""},"item_3":{"orig":"images/0001-3.jpg","main":"images/large/0001-3.jpg","thumb":"images/small/0001-3.jpg","label":""},"item_4":{"orig":"images/0001-4.jpg","main":"images/large/0001-4.jpg","thumb":"images/small/0001-4.jpg","label":""}},"type":"simple","video":false}}'), </script> 

your appreciated. in advance

try :

return json(album, jsonrequestbehavior.allowget);  

instead of :

return view(album); 

hope help.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -