fill dropdown in razor pages in asp.net core or fill dropdown in razor or core or fill dropdown in razor pages in core
C# Code
public SelectList mItem_List2 { get; set; }
public List<SelectListItem> mItem_List { get; set; }
public List<SelectListItem> Options { get; set; }
public IActionResult OnGet()
{
var data4 = from x in _context.mItem
orderby x.IName
select (new SelectListItem() { Value = x.mIcode, Text = x.IName + ", " + x.Item_ID });
mItem_List = data4.ToList();
Options = _context.mItem.Select(a =>
new SelectListItem
{
Value = a.mIcode,
Text = a.IName+", "+a.Item_ID
}).ToList();
object selectedItem = null;
var data5 = from x in _context.mItem
orderby x.IName
select x;
mItem_List2 = new SelectList(data5.AsNoTracking(), "mIcode", "IName", selectedItem);
return Page();
}
Html code
<select asp-for="ItemI.mIcode" class="form-control"
asp-items="@Model.Options">
<option value="">-- Select Department --</option>
</select>
<select asp-for="ItemI.mIcode" class="form-control"
asp-items="@Model.mItem_List">
<option value="">-- Select Department --</option>
</select>
<select asp-for="ItemI.mIcode" class="form-control"
asp-items="@Model.mItem_List2">
<option value="">-- Select Department --</option>
</select>
C# Code
public SelectList mItem_List2 { get; set; }
public List<SelectListItem> mItem_List { get; set; }
public List<SelectListItem> Options { get; set; }
public IActionResult OnGet()
{
var data4 = from x in _context.mItem
orderby x.IName
select (new SelectListItem() { Value = x.mIcode, Text = x.IName + ", " + x.Item_ID });
mItem_List = data4.ToList();
Options = _context.mItem.Select(a =>
new SelectListItem
{
Value = a.mIcode,
Text = a.IName+", "+a.Item_ID
}).ToList();
object selectedItem = null;
var data5 = from x in _context.mItem
orderby x.IName
select x;
mItem_List2 = new SelectList(data5.AsNoTracking(), "mIcode", "IName", selectedItem);
return Page();
}
Html code
<select asp-for="ItemI.mIcode" class="form-control"
asp-items="@Model.Options">
<option value="">-- Select Department --</option>
</select>
<select asp-for="ItemI.mIcode" class="form-control"
asp-items="@Model.mItem_List">
<option value="">-- Select Department --</option>
</select>
<select asp-for="ItemI.mIcode" class="form-control"
asp-items="@Model.mItem_List2">
<option value="">-- Select Department --</option>
</select>
No comments:
Post a Comment