0

this is my controller action method

  public ActionResult GetAppComp(int id, string name, int cloudType, string appCompID)
    {

        var appComp = db.ApplicationComponents.ToList();
        var model = appComp.Where(p => p.ApplicationID == id).ToList();
        ViewBag.ApplicationComponent = db.ApplicationComponents.Where(p => p.ApplicationID == id).ToList();

        ViewBag.ApplicationName = db.Applications.Where(p => p.ApplicationID == id).FirstOrDefault();
        ViewBag.ApplicationID = db.ApplicationComponents.Select(p => p.ApplicationID);
        return PartialView("_TechnicalFitment", model);

    }

from this action method I am trying to pass the data to Partial View i.e. "_TechnicalFitment" through view bag, as my viewbag is taking all the values.

In my partial view I need to populate the list of Application Component in a div i.e.

<div id="surveyProgress" class="surveyProgress">

</div>

I am using a jquery

 <script>

 process();
 function process(){
 var appComp=@Viewbag.ApplicationComponent ;
 $('#surveyProgress').append('<ul></ul>');
   for (var i = 0; i<appComp.length; i++ ) {

       $('#surveyProgress'+ '> ul' ).append('<li class="AppComponent-'  + i + '"> <span>'+ appComp[i].name</span></li>');

 }
 </script>

But I cant fetch the list of components in div. Help!!

  • It would need to be `var appComp=@Html.Raw(Json.Encode(Viewbag.ApplicationComponent));` but why are you doing in in jquery? Just use a `foreach` loop in the view to loop through the `ViewBag` property (although the best approach would be to use a view model with a property `IEnumerable` , not `ViewBag`) –  Aug 12 '17 at 13:38
  • thank you .. now doing with view bag – Deepshikha Sharma Aug 12 '17 at 13:48

0 Answers0