Guest User

Guest User

  • Tech Writer
  • 611
  • 128.1k

Null value in error mvc.

Aug 7 2020 3:51 AM
I want to click a viewDetails button and show user profile. But I have faced an issue.
 
it's me get code
  1. public IActionResult UserDetail(int? UserId)-Here null userid  
  2. {  
  3. UserViewFullDetail obj_Detail = new UserViewFullDetail();  
  4. try  
  5. {  
  6. var Result = (from UM in _context.UserProfileMaster  
  7. join U in _context.UserMaster on UM.UserId equals U.UserId  
  8. where UM.UserId == U.UserId  
  9. where Convert.ToBoolean(UM.UserId == UserId)  
  10. select new  
  11. {  
  12. UM.UserImage,  
  13. UM.FirstName,  
  14. UM.MobileNumber,  
  15. UM.Country,  
  16. UM.UserId,  
  17. UM.ZipCode,  
  18. UM.InstaUserName,  
  19. UM.LevelBaseBall,  
  20. UM.Address,  
  21. U.Dob  
  22. }).FirstOrDefault();  
  23. if (Result != null)  
  24. {  
  25. obj_Detail.Name = Result.FirstName;  
  26. DateTime dt = Convert.ToDateTime(Result.Dob);  
  27. obj_Detail.DOB = string.Format("{0:dd MMMM yyyy}", dt);  
  28. var Mob = Result.MobileNumber;  
  29. obj_Detail.MobileNumber = String.Format("{0:##########}"double.Parse(Mob));  
  30. obj_Detail.Country = Result.Country;  
  31. obj_Detail.UserImage = Result.UserImage;  
  32. obj_Detail.InstaUserName = Result.InstaUserName;  
  33. obj_Detail.Address = Result.Address;  
  34. obj_Detail.LevelBaseBall = Result.LevelBaseBall;  
  35. it's me view code  
  36. @model NBP_BaseBallAdmin.ViewModel.UserViewFullDetail  
  37. @{  
  38. ViewData["Title"] = "UserDetail";  
  39. Layout = "~/Views/Shared/_Layout.cshtml";  
  40. }  
  1. <!-- Body Content Wrapper -->  
  2. <div class="ms-content-wrapper categories">  
  3. <div class="row">  
  4. <div class="col-md-12">  
  5. <nav aria-label="breadcrumb">  
  6. <div class="row">  
  7. <div class="col-md-6">  
  8. <ol class="breadcrumb pl-0">  
  9. <li class="breadcrumb-item"><a href="">User Management</a></li>  
  10. <li class="breadcrumb-item active" aria-current="page">User Detail</li>  
  11. </ol>  
  12. </div>  
  13. <div class="col-md-6">  
  14. <div class="invoice-buttons text-right">  
  15. <a href="#" class="btn btn-danger" data-toggle="modal" data-target="#warning-user">Report User</a>  
  16. </div>  
  17. </div>  
  18. </div>  
  19. </nav>  
  20. <div class="ms-panel">  
  21. <div class="ms-panel-header">  
  22. <div class="d-flex justify-content-between">  
  23. <div class="align-self-center align-left ">  
  24. <h6>User Details</h6>  
  25. </div>  
  26. <div class="col-md-6">  
  27. <div class="invoice-buttons text-right">  
  28. <a href="player-stats.html" class="btn btn-dark mr-2">View Stats</a>  
  29. <a href="update-user.html" class="btn btn-info">Update Profile</a>  
  30. </div>  
  31. </div>  
  32. </div>  
  33. </div>  
  34. <div class="ms-panel-body">  
  35. <div class="row">  
  36. <div class="col-lg-3">  
  37. <div class="master-img">  
  38. <img src=" @Html.DisplayFor(x => x.UserImage)" alt="doctor-img">  
  39. </div>  
  40. </div>  
  41. <div class="col-lg-9">  
  42. <div class="detail-sec">  
  43. <div class="d-flex align-item-center justify-content-between">  
  44. <h5 class="bold text-capitalize">William Rose</h5>  
  45. </div>  
  46. <ul class="Consultant-info">  
  47. @Html.HiddenFor(x => x.UserId)  
  48. <li><p>Instagram Username:</p> <span> @Html.DisplayFor(x => x.InstaUserName)</span></li>  
  49. <li><p>Date of Birth:</p> <span> @Html.DisplayFor(x => x.DOB)</span></li>  
  50. <li><p>Mobile no:</p><span> @Html.DisplayFor(x => x.MobileNumber) </span></li>  
  51. <li><p>Country:</p> <span> @Html.DisplayFor(x => x.Country)</span></li>  
  52. <li><p>Level of Baseball:</p> <span>@Html.DisplayFor(x => x.LevelBaseBall)</span></li>  
  53. <li><p>Zipcode:</p> <span>@Html.DisplayFor(x => x.ZipCode)</span></li>  
  54. <li><p>Address:</p><span>@Html.DisplayFor(x => x.ZipCode) </span></li>  
  55. </ul>  
  56. </div>  
  57. </div>  
  58. </div>  
  59. </div>  
  60. </div>  
Please check this

Answers (1)