ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,344 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I want to sort question by ascending order , the below statement in bold is giving error , please suggest
public async Task<IActionResult> Details(int? id)
{
if (id == null || _context.Questions == null)
{
return NotFound();
}
var question = await _context.Questions.FirstOrDefaultAsync(m => m.Sno == id);
**question = question.OrderBy(m => m.Sno);**
if (question == null)
{
return NotFound();
}
return View(question);
}
the variable question is a single entity, not a collection that can be sorted. maybe you wanted to sort before picking one:
var question = await _context.Questions
.OrderBy(m => m.Sno)
.FirstOrDefaultAsync(m => m.Sno == id);