Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
V

vanilsonwdd

@vanilsonwdd
About
Posts
2
Topics
2
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Save Foreign Key Value - EF Core + ASP.NET Core
    V vanilsonwdd

    Hi guys, I´m new to ASP.NET Core and EF Core and I have the following problem: I have two related objects, Goals and Months, Goals got the foreign key of Months, and when I try to save the data of goals I got a foreign key error because the value of MonthId is 0, but when I create the select in the HTML I got correct code value. Description of the error: SqlException: The INSERT statement conflicted with the FOREIGN KEY constraint FK_Goals_MonthId;. The conflict occurred in database Portal_RNT, table dbo.Months , column MonthId;. The statement has been terminated. Here is the code: HTML

    @model ProjectName.Models.Goals

    <form asp-controller="Goals" asp-action="Create">
    Other form elements

      <select name="months" asp-for="MonthId" class="form-control" asp-items="ViewBag.Months">
    
      </select>
    
      <input type="submit" value="Save" class="btn btn-primary" />
    

    </form>

    Goals Model

    public class Goals
    {
    [Display(Name = "Code")]
    public Int32 GoalId { get; set; }

        public String GoalName{ get; set; }
        public Months Month{ get; set; }
        public Int32 MonthId{ get; set; }
        ....
        Other properties
    
    }
    

    Month Model

    public class Months
    {
        \[Key\]
        \[Display(Name = "Code")\]
        public Int32 MonthId { get; set; }
        \[Display(Name = "Designation")\]
        public String Designation{ get; set; }
    }
    

    Goals Controller

    public IActionResult Create(Goals goal)
    {
    if (ModelState.IsValid)
    {
    _context.Goals.Add(goal);
    _context.SaveChanges();
    }
    return View("~/../Create.cshtml");
    }

    Best Regards

    ASP.NET asp-net help csharp html database

  • How to get the select value in a multiple dropdownlist
    V vanilsonwdd

    hi, I'm trying to get multiple values that was selected in a dropdown list, the problem is that it's only returning one value, if I select two or more values only give me one, here's the code:

    List dep = new List();
    foreach (ListItem item in sltnamedep.Items)
    {

            if (item.Selected)
            {
    
    
                
                dep.Add(item.Text);
    
    
            }
    
        }
        for (int i = 0; i < dep.Count; i++)
            Response.Write(dep\[i\]);
    
    C# help tutorial
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups