Balwant Singh

Balwant Singh

  • 1.6k
  • 333
  • 13.2k

Select List Selected .NET Core

Jan 1 2020 10:48 PM
I have and String in ViewBag.SubjectName="Hindi"
 
How Get Selected Item Select in Select List Selected .NET Core
 
<div>Subject :@foreach (var t in ViewBag.SubjectName)
{@t} , Topic : @foreach (var t in ViewBag.TopicName)
{@t} </div>
<div class="col-md-4">
<form asp-action="EditSubTopic">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<input type="hidden" asp-for="SubTopicID" />
<div class="form-group">
<label class="control-label"></label>
<select id="SubjectID" class="form-control" asp-items="@(new SelectList(@ViewBag.SubjectList,"SubjectID","SubjectName"))"></select>
</div>
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="TopicID" class="control-label"></label>
<select asp-for="TopicID" class="form-control" asp-items="@(new SelectList(string.Empty,"TopicID","TopicDisplayName"))"></select>
</div>
 
 

Brought to you by:

Answers (6)