Paul Drake

Paul Drake

  • NA
  • 37
  • 4.1k

Not sure how to convert int to C# object

Dec 24 2020 11:09 PM
I'm trying to pass a parameter to a controller method and I'm having problems with converting type int to C# object. Or more specifically type in to root.
  1. @{  
  2.  Layout = null;  
  3.  Root movieResult = ViewData["movies"] as Root;  
  4.  MovieResults movies = ViewData["movies"] as MovieResults;  
  5. }  
  6. <!doctype html>  
  7. <html lang="en">  
  8. <head>  
  9.     <meta charset="UTF-8"/>  
  10.     <meta name="viewport" content="width=device-width, initial-scale=1"/>  
  11.     <title>Movie Streaming Availability App</title>  
  12.     <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">  
  13.     <link rel="stylesheet" type="text/css" href="css/site.css">  
  14. </head>  
  15. <body>  
  16. <main>  
  17.     <div class="container">  
  18.         <div class="row">  
  19.  @foreach (var movie in movies.Results)  
  20.  {  
  21.  <div class="col-3">  
  22.                     <a asp-controller="Movie" asp-action="MoviePage" asp-route-Id="@movie.Id"><img src="https://image.tmdb.org/t/p/w300/@movie.PosterPath" alt="@movie.Title"></a>  
  23.                     <label>@movie.Title</label>  
  24.                 </div>  
  25.  }  
  26.  </div>  
  27.     </div>  
  28. </main>  
  29. <footer>  
  30.     <script type="text/javascript" src="lib/jquery/dist/jquery.js"></script>  
  31.     <script type="text/javascript" src="lib/bootstrap/dist/js/bootstrap.bundle.js"></script>  
  32.     <script type="text/javascript" src="~/js/site.js" asp-append-version="true"></script>  
  33. </footer>  
  34. </body>  
  35. </html>  

Answers (3)