Marcoelho97
Marcoelho97
CC#
Created by Marcoelho97 on 4/10/2023 in #help
❔ I apparently have an infinite loop, but I can't fix it to work
30 replies
CC#
Created by Marcoelho97 on 12/18/2022 in #help
❔ Asp-all-route-data's initial value is changed with asp-route-*
So, I have:
var parms = new Dictionary<String, String>
{
{"Nome", Nome.ToString() },
};
var parms = new Dictionary<String, String>
{
{"Nome", Nome.ToString() },
};

And I have
@foreach (Tipo tipo in ViewBag.Tipos)
{
<div>
<a asp-all-route-data="parms" asp-route-Nome="@tipo.Id">@tipo.Nome</a>
</div>
}
@foreach (Tipo tipo in ViewBag.Tipos)
{
<div>
<a asp-all-route-data="parms" asp-route-Nome="@tipo.Id">@tipo.Nome</a>
</div>
}
After this foreach, my parms value will have changed tot he last one in my ViewBag.Tipos I don't understand why this is happening and/or how to prevent it :(
2 replies
CC#
Created by Marcoelho97 on 12/16/2022 in #help
❔ System.NullReferenceException 'Object reference not set to an instance of an object.'
Hello! I'm getting a little desperate here: This is my index code:
public IActionResult Index()
{
// List<Tipo> list = _context.Tipos.ToList();
List<string> list = new List<string>();
list.Add("Home");
list.Add("Home");
list.Add("Home");
list.Add("Home");
return View(list);
}
public IActionResult Index()
{
// List<Tipo> list = _context.Tipos.ToList();
List<string> list = new List<string>();
list.Add("Home");
list.Add("Home");
list.Add("Home");
list.Add("Home");
return View(list);
}
This is my index.cshtml:
<select class="form-select" name="tipo" id="tipo">
@foreach (var item in Model)
{
<option value="abc">abc</option>
}
</select>
<select class="form-select" name="tipo" id="tipo">
@foreach (var item in Model)
{
<option value="abc">abc</option>
}
</select>
Why do I get this exception? I've been at it for over an hour, I'm new at this, and I'm very confused
7 replies
CC#
Created by Marcoelho97 on 12/11/2022 in #help
✅ Multiple one to many relationships
I've just recently started using ASP.NET and I ran into a bit of a wall Basically:
public class Reserva
{
public int Id { get; set; }

public string ClienteId { get; set; }
public ApplicationUser Cliente { get; set; }

public string FuncionarioId { get; set; }
public ApplicationUser Funcionario { get; set; }
}

public class ApplicationUser : IdentityUser
{
public Empresa? Empresa { get; set; }
public ICollection<Reserva> Reservas { get; set; }
public ICollection<Reserva> EntregasRecolhas { get; set; }

}
public class Reserva
{
public int Id { get; set; }

public string ClienteId { get; set; }
public ApplicationUser Cliente { get; set; }

public string FuncionarioId { get; set; }
public ApplicationUser Funcionario { get; set; }
}

public class ApplicationUser : IdentityUser
{
public Empresa? Empresa { get; set; }
public ICollection<Reserva> Reservas { get; set; }
public ICollection<Reserva> EntregasRecolhas { get; set; }

}
How do I make a migration of this? I'm getting "Unable to determine the relationship represented by navigation 'ApplicationUser.EntregasRecolhas' of type 'ICollection<Reserva>'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'." And I don't know how to proceed without having to manually do it ( which I don't know how to do it either )
7 replies