© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
7 replies
mer_nam hai bulla rakhta hu kula

❔ Models data is not showing in view with help of ViewData

I have created model and passed its data with ViewData like this-
Controller Code-->
IEnumerable<SelectListItem> CoverTypeList = _UnitOfWork.CoverType.GetAll().Select(
u => new SelectListItem
{
Text = u.Name,
Value = u.Id.ToString(),
}
);
if (id == null || id == 0)
{
ViewData["CoverTypeList"] = CoverTypeList;
return View(product);
}

<--- to View-->
<label asp-for="CoverTypeId"></label>
<select asp-for="CoverTypeId" asp-items="@(ViewData["CoverTypeId"] as IEnumerable<SelectListItem>)" class="form-select">
<option disabled selected>--Select CoverType--</option>
</select>
<span asp-validation-for="CategoryId" class="text-danger"> </span>

<---Model--->
namespace BulkyBook.Models
{
public class CoverType
{
[Key]
public int Id { get; set; }

[Display(Name ="Conver Type")]
[Required]
[MaxLength(100)]
public string Name { get; set; }
}
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Data Grid View is not showing data.
C#CC# / help
2y ago
MVVM - View model with collection of view models?
C#CC# / help
3y ago
datagridview not showing data
C#CC# / help
6mo ago
❔ im using models with tuple in razor view but it doesn't send data to action
C#CC# / help
3y ago