Jump to content
rsd_17

InvalidOperationException: Could not create an instance of type 'Microsoft.AspNetCore.Http.HttpContext'. Model bound complex types must not be abstract or value types and must have a parameterless constructor. Alternatively, give the 'contexto' parameter

Recommended Posts

rsd_17

Ola, 

Estou a ter um erro no programa quando clico em "Perfil" na layout, o erro que aparece é este

InvalidOperationException: Could not create an instance of type 'Microsoft.AspNetCore.Http.HttpContext'. Model bound complex types must not be abstract or value types and must have a parameterless constructor. Alternatively, give the 'contexto' parameter a non-null default value.

O programa tem login por contas e quero enviar o id do utilizador logado para a view de forma a que ele saiba qual o utilizador que se encontra logado e possa apresentar o seu perfil com os detalhes, possa edita-lo ou apaga-lo.

No metodo da view de perfil tentei enviar o id para a view desta forma

 public IActionResult PerfilSocio( HttpContext contexto,int? id)
        {
            int x = Convert.ToInt32(contexto.Session.GetInt32("UserId"));
            
            if (id == x)
            {

                foreach (var item in _context.Socios)
                {
                    if (item.Idsocio == x)
                    {
                        var y = item;
                        return View(y);

                    }
                }
                
            }
            else
            {
                return View("NaoEncontrado");
            }
            return View();
        }

Mas aparece-me aqele erro quando carrego sobre perfil, alguem me pode ajudar a resolver por favor ?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.