79237413

Date: 2024-11-29 14:27:05
Score: 1
Natty:
Report link

I found a solution. I had two lines to replace in my controller:

ViewData["ApplicationUserId"] = new SelectList(_context.Users, "Id", "Id");
ViewData["ApplicationUserId"] = new SelectList(_context.Users, "Id", "Id", article.ApplicationUserId);

So I created two methods in 'ArticlesRepository.cs':

        public SelectList  GetUser()
    {
        var idUser = new SelectList(_context.Users, "Id", "Id");

        return idUser;
    }
    public SelectList  GetUserWithArticle(Articles article)
    {
        var idUser = new SelectList(_context.Users, "Id", "Id", article.ApplicationUserId);

        return idUser;
    }

and, in 'IArticlesRepository.cs':

    SelectList GetUser();
    SelectList GetUserWithArticle(Articles article);

Which gives, in the new controller:

ViewData["ApplicationUserId"] = _repo.GetUser();
ViewData["ApplicationUserId"] = _repo.GetUserWithArticle(article);

It works. Thanks!

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: AMP59