Sourabh Dhiman

Sourabh Dhiman

  • 1.7k
  • 298
  • 10.4k

Error in mvc view.

Aug 1 2020 6:13 AM
it's my data get code in mvc when page reload.
  1. public IActionResult EducationalVideo()  
  2. {  
  3. List<EducationalVideoViewModel> lst = new List<EducationalVideoViewModel>();  
  4. try  
  5. {  
  6. var Video = _context.TblEducationalVideo.ToList();  
  7. if (Video != null)  
  8. {  
  9. foreach (var item in Video)  
  10. {  
  11. EducationalVideoViewModel lst_Data = new EducationalVideoViewModel();  
  12. lst_Data.Name = item.Name;  
  13. lst_Data.Video = item.VideoPath;  
  14. lst.Add(lst_Data);  
  15. }  
  16. }  
  17. else  
  18. {  
  19. ViewBag.message = "No Record !";  
  20. }  
  21. }  
  22. catch(Exception ex)  
  23. {  
  24. ViewBag.message = "Internal Server Error";  
  25. var message = ex.InnerException.Message;  
  26. throw;  
  27. }  
  28. return View(lst);  
  29. }  
it's me viewmodel classes
  1. public class EducationalVideoViewModel  
  2. {  
  3. public string Name { getset; }  
  4. public string Video { getset; }  
  5. }  
  6. public class EducationalVideoList  
  7. {  
  8. public List<EducationalVideoViewModel> lst_EducationData { get;set; }  
  9. public string Name { getset; }  
  10. public string Video { getset; }  
  11. public string Image { getset; }  
  12. }  
it's view code
  1. @foreach (var item in Model.lst_EducationData)-Here i have face issue null value.  
  2. {  
  3. <tr class="Search">  
  4. <td>@{ Srno++; } @Srno </td>  
  5. <td>  
  6. <div class="video-frame">  
  7. <video width="200" height="140" controls>  
  8. <source src="http://nbpbaseball.harishparas.com/UploadVideo/@Url.Content(item.Video)" type="video/mp4">  
  9. </video>  
  10. </div>  
  11. </td>  
  12. <td>@Html.DisplayFor(x => item.Name)</td>  
  13. <td>  
  14. <a href="#" class="btn btn-danger"><i class="fa fa-trash"></i> Delete</a>  
  15. </td>  
  16. </tr>  
  17. }  

Brought to you by: JavaScript SDK for Bold BI dashboard and analytics embedding. Free trial.

Answers (2)