Guest User

Guest User

  • Tech Writer
  • 611
  • 127.8k

Get Only Single Value Error

Jul 15 2020 8:05 AM
It's me c# code . I have get value from database using this code.Run this code but view only one record.
public IActionResult UserManagement()
{
UserViewModel obj = new UserViewModel();
List<UserViewModel> lst = new List<UserViewModel>();
try
{
var Result = _context.UserProfileMaster.ToList();
if (Result.Count > 0)
{
foreach (var item in Result)
{
obj.FullName = item.FirstName + " " + item.LastName;
obj.DOB = Convert.ToDateTime(item.Dob);
var Mob = item.MobileNumber;
obj.MobileNumber = String.Format("{0:+##-##########}", double.Parse(Mob));
obj.Country = item.Country;
obj.UserImage = item.UserImage;
}
}
else
{
ViewBag.message = "No Record !";
}
}
catch (Exception ex)
{
ViewBag.message = "Internal Server Error";
var message = ex.InnerException.Message;
throw;
}
return View(new List<UserViewModel> { obj });
}
 
 
It's me view code.
<tbody>
@foreach (var item in Model)
{
<tr>
<td>1.</td>@*<img src="@Url.Content(Model.ImagePath)" alt="Image" />*@
<td><img src="@Url.Content(item.UserImage))" alt="image">@Html.DisplayFor(x => item.FullName)</td>
<td>@Html.DisplayFor(x => item.DOB)</td>
<td>@Html.DisplayFor(x => item.MobileNumber)</td>
<td>@Html.DisplayFor(x => item.Country)</td>
<td><a href="" class="btn btn-primary">View Detail</a></td>
</tr>
  check this  

Answers (4)