question

sblb-6958 avatar image
0 Votes"
sblb-6958 asked sblb-6958 edited

EF one-to-many to assure the link with the main table.

Hi,
I would like to do a link between main table Developer & a table ActionList.

The ActionList take place in edit mode of my app to the address : "/developer/edit/{developerId:int}"

I try to use EF one-to-many to do the link between two tables

I structured the model class has below :

 public partial class Developer
      {
          public int Id { get; set; }
           public ICollection<ActionsList>? ActionsLists { get; set; }
   }
        
   public class ActionsList
      {
          [Key]   
          public int ActionId { get; set; }            
             
          public DateTime ProductionDate { get; set; }
                
          public int DeveloperId { get; set; }
          public Developer Developer { get; set; }
        
      }

application data :

  public class ApplicationDBContext : DbContext
      {
          public ApplicationDBContext(DbContextOptions<ApplicationDBContext> options) : base(options)
          {
          }
          public DbSet<Developer> Developers { get; set; }
          public DbSet<ActionsList> ActionsLists { get; set; }
                       
            
          protected override void OnModelCreating(ModelBuilder modelBuilder)
          {
              modelBuilder.Entity<ActionsList>()
                          .HasOne<Developer>(s => s.Developer)
                          .WithMany(g => g.ActionsLists)
                          .HasForeignKey(s => s.DeveloperId);       
          }   
            
        }

when I want to add the actions in page https://localhost:44354/developer/edit/1 this means all actions for developerId = 1 ; any value has posted in ActionList.

But when I've put the break point await http.PostAsJsonAsync("api/actionslist", act); I see that ActionId = null .

I guess that I set up EF one-to-many wrong!

Can you help me how to link the two tables? (This is the first time I've done this)

Thanks in advance








dotnet-aspnet-core-blazor
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @sblb-6958,

The One-to-Many configuration seems correct in above post. More detail information about One-to-Many relationship, see :

One-to-Many Relationship Conventions in Entity Framework Core

Configure One-to-Many Relationships using Fluent API in Entity Framework Core.

But when I've put the break point await http.PostAsJsonAsync("api/actionslist", act); I see that ActionId = null .

Do you mean after calling the API method, the ActionId in the return data is null? From your code, the ActionId is the primary key, by default it is identity and will auto-insert, if it is null, first, you can check the database via the SSMS, whether the ActionsList table contains the relates data. Second, you can check the API method, whether it get the correct data from the database, and the return data is not null. If the issue relates the API method, can you share the relate code?
0 Votes 0 ·
AgaveJoe avatar image
0 Votes"
AgaveJoe answered sblb-6958 edited

Against my better judgement, I created an example. This is an example NOT a solution. In production code you would NOT pass entities between the client and Web API! Typically you would designed a data interrace and pass poco classes.

I used followed the following documentation which I have provided many times over many of your threads.

Tutorial: Create a web API with ASP.NET Core
Saving Related Data

Entities

     public partial class Developer
     {
         public int DeveloperId { get; set; }
         public List<ActionItem>? ActionItems { get; set; }
     }
    
     public class ActionItem
     {
         public int ActionItemId { get; set; }
         public string? Tilte { get; set; }
         public string? Description { get; set; }
         public string? State { get; set; }
         public DateTime? OpenDate { get; set; }
         public DateTime? PlanDate { get; set; }
         public DateTime? CloseDate { get; set; }
    
         public int DeveloperId { get; set; }
         public Developer? Developer { get; set; }

Related data configuration

         protected override void OnModelCreating(ModelBuilder modelBuilder)
         {
             modelBuilder.Entity<ActionItem>()
                 .HasOne(d => d.Developer)
                 .WithMany(d => d.ActionItems);
         }

Controller

     [Route("api/[controller]")]
     [ApiController]
     public class DeveloperActionController : ControllerBase
     {
         private readonly WebApiSqliteContext _context;
         public DeveloperActionController(WebApiSqliteContext context)
         {
             _context = context;
         }
         // GET: api/<DeveloperActionController>
         [HttpGet]
         public IEnumerable<Developer> GetDevelopersWithActions()
         {
             return _context.Developers.Include(a => a.ActionItems).ToList();
         }
    
         // GET api/<DeveloperActionController>/5
         [HttpGet("{id}")]
         public async Task<ActionResult<Developer>> GetDeveloperActions(int id)
         {
             Developer? developer = await _context.Developers
                 .Include(a => a.ActionItems)
                 .FirstOrDefaultAsync(d => d.DeveloperId == id);
    
             if (developer == null)
             {
                 return NotFound();
             }
    
             return Ok(developer);
         }
    
         // POST api/<DeveloperActionController>
         [HttpPost]
         public async Task<ActionResult<Developer>> PostAsync([FromBody] Developer developer)
         {
             _context.Developers.Add(developer);
             await _context.SaveChangesAsync();
    
             return CreatedAtAction(nameof(GetDeveloperActions), new { id = developer.DeveloperId }, developer);
         }
    
         // PUT api/<DeveloperActionController>/5
         [HttpPut("{id}")]
         public async Task<ActionResult<Developer>> Put(int id, [FromBody] ActionItem actionItem)
         {
             Developer? developer = await _context.Developers
                 .Include(a => a.ActionItems)
                 .FirstOrDefaultAsync(d => d.DeveloperId == id);
    
             if (developer == null)
             {
                 return NotFound();
             }
    
             developer.ActionItems.Add(actionItem);
             await _context.SaveChangesAsync();
    
             return CreatedAtAction(nameof(GetDeveloperActions), new { id = developer.DeveloperId }, developer);
    
         }
    
         // DELETE api/<DeveloperActionController>/5
         [HttpDelete("{id}")]
         public async Task<IActionResult> Delete(int id)
         {
             Developer? developer = await _context.Developers
                 .Include(a => a.ActionItems)
                 .FirstOrDefaultAsync(d => d.DeveloperId == id);
    
             if (developer == null)
             {
                 return NotFound();
             }
    
             _context.Remove(developer);
    
             await _context.SaveChangesAsync();
    
             return NoContent();
         }
     }

Post data

 {
   "developerId": 0,
   "actionItems": [
     {
       "actionItemId": 0,
       "tilte": "Action Title",
       "description": "Description",
       "state": "State",
       "openDate": "2022-11-17",
       "planDate": "2022-11-17",
       "closeDate": "2022-11-17",
       "developerId": 0
     }
   ]
 }

Put data

 {
   "actionItemId": 0,
   "tilte": "Action Title 2",
   "description": "Description 2",
   "state": "State 2",
   "openDate": "2022-11-18",
   "planDate": "2022-11-18",
   "closeDate": "2022-11-18",
   "developerId": 1
 }


Configuration is needed to return a entity otherwise you'll get an error.

 builder.Services.AddControllers().AddJsonOptions(x =>
                 x.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles);


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

sblb-6958 avatar image
0 Votes"
sblb-6958 answered

I changed the application data as below

   public class ApplicationDBContext : DbContext
       {
           public ApplicationDBContext(DbContextOptions<ApplicationDBContext> options) : base(options)
           {
           }
           public DbSet<Developer> Developers { get; set; }
           public DbSet<ActionsList> ActionsLists { get; set; }                     
                 
         }

I changed the model class as below

  public partial class Developer
       {
           public int Id { get; set; }
           public ICollection<ActionsList>? ActionsLists { get; set; }
    }
            
    public class ActionsList
       {
           [Key]   
           public int ActionId { get; set; }            
                 
           public DateTime ProductionDate { get; set; }
                    
           public int Id { get; set; }
           public Developer Developer { get; set; }
            
       }


After that I've made a migration and the foreign key was created DeveloperId. The result of the migration is

    constraints: table =>
                 {
                     table.PrimaryKey("PK_ActionsLists", x => x.Id);
                     table.ForeignKey(
                         name: "FK_ActionsLists_Developers_DeveloperId",
                         column: x => x.DeveloperId,
                         principalTable: "Developers",
                         principalColumn: "Id");
                 });
    
             migrationBuilder.CreateIndex(
                 name: "IX_ActionsLists_DeveloperId",
                 table: "ActionsLists",
                 column: "DeveloperId");

But I can't make the link between /developer/edit/{developerId:int}" and the actions await http.PostAsJsonAsync("api/actionslist", act)

This can be translated as follows:
/developer/edit/1 ==> eg 4 actions have been created for line 1 edited
/developer/edit/2 ==> eg 10 actions have been created for line 2 edited

also in edit page I would like to see only actions concerning /developer/edit/1 or /developer/edit/2.

I will appreciate your help!

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

sblb-6958 avatar image
0 Votes"
sblb-6958 answered sblb-6958 edited

@ZhiLv-MSFT thanks to your comments

Do you mean after calling the API method, the ActionId in the return data is null?

It's ok ActionId is not null and auto-insert.

As you can see in the picture below that I've Id et DeveloperId column.

the Id column is in the class model definition and DeveloperId was created automatically
This means that DeveloperId is the foreign key according to the class model below

public partial class Developer
{
public int Id { get; set; }
public ICollection<ActionsList>? ActionsLists { get; set; }
}

public class ActionsList
{
[Key]
public int ActionId { get; set; }

public DateTime ProductionDate { get; set; }

public int Id { get; set; }
public Developer Developer { get; set; }

}

![260000-image.png][1]

the action method is

[HttpGet]
public async Task<IActionResult> Get()
{
var actions = await _contexts.ActionsLists.ToListAsync();
return Ok(actions);
}

[HttpGet("{id}")]
public async Task<IActionResult> Get(int id)
{
var action = await _contexts.ActionsLists.FirstOrDefaultAsync(a => a.Id == id);
return Ok(action);
}

[HttpPost]
public async Task<IActionResult> Post(ActionsList actions)
{
_contexts.Add(actions);
await _contexts.SaveChangesAsync();
return Ok(actions.ActionId);
}

How I can see only the actions for the page /developer/edit/1 ? because right now I see all actions for each edit page




[1]: /answers/storage/attachments/260000-image.png





image.png (6.9 KiB)
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

But when I've put the break point await http.PostAsJsonAsync("api/actionslist", act); I see that ActionId = null .

You did not share the how "act" is populated and the Post action only accepts a single ActionList item. Secondly, it is impossible for the ActionId to be null since the default value of an int is zero! Where are you seeing a null ActionId?

If the intent is adding ActionList items to the Developer entity then the action should contains a Developer parameter or, at the very least, the developer Id. At this point, the design does not make logical sense. Even the naming is odd. For example, ActionList is not a list it is a single item.

If all you're trying to do is save related data then simply populate the entities and save the changes. This pattern is openly illustrated in the official documentation.

Saving Related Data

0 Votes 0 ·

You did not share the how "act" is populated

In Edit.razor page

 <SidepanelComponent @ref="createSidepanel" Title="Create" SubTitle="Actions">
     <FormCreateSidePanel  ButtonAction="Create" act="@act" OnValidSubmit="@CreateActionsList" />
 </SidepanelComponent>
    
 @code {
    
 ActionsList act = new ActionsList();
    
 async Task CreateActionsList()
     {
            
       await http.PostAsJsonAsync("api/actionslist", act);
       uriHelper.NavigateTo($"/developer/edit/{developerId}");
     }   
    
 }

it is impossible for the ActionId to be nul

You right, I've done a mistake.


If the intent is adding ActionList items to the Developer entity

It's not quite that. For each Developer Id I want to add several actions. How I can do that.

Plus I tried to create foreign key in ActionsList ; DevoloperId. But I don't know how I can add several actions for one Id's developer?
eg.
![260213-image.png][1]

In this case DeveloperId correspond to https://localhost:44354/developer/edit/1
I guess I have to modify the Post action

ActionList is not a list it is a single item.

Why the ACtionslist is not a list? I defined the class model for the ACtionsList and I definied the Icollection<ActionsList> in developer class


[1]: /answers/storage/attachments/260213-image.png

0 Votes 0 ·
image.png (3.6 KiB)

The code you shared is vastly different from your expectations.

For each Developer Id I want to add several actions. How I can do that.

The Saving Related Data link I provided in my last post contains the standard pattern. Simply populate the entities with data, add, and save.

Why the ACtionslist is not a list?

I think you confused yourself because you name the class ActionList but the class is NOT a list. To make matters ever more confusing you used Visual Studio to create an ActionList controller. Your ActionList controller is operating on a single item not a list!

Create a DeveloperController or DeveloperActionController. Add an action where the Id is the delevoperId and the action parameter is a List<ActionsItem>. The client application passes the List<ActionsItem> and Id route parameter. The action simply follows the Saving Related Data pattern already suggested.

0 Votes 0 ·
sblb-6958 avatar image
0 Votes"
sblb-6958 answered AgaveJoe commented

I follow up your recommendation and I rename the controller and the class model.
the controller name is : DeveloperActionsController
the class model name is : ActionItem.

I come back to the initial problem.
I follow up the link configure-one-to-many-relationship-using-fluent-api-in-ef-core.aspx to create the foreign key to link the main table Developer with ActionItem table.

I've put the break point to [HttpPost] and I obtained : PRimaryKey ActionId= 0 and the ForeignKey CurrentActionId = 0
Do you see my mistake?

   [HttpPost]
         public async Task<IActionResult> Post(ActionItem actions)
         {
             _contexts.Add(actions);
             await _contexts.SaveChangesAsync();
             return Ok(actions.ActionId);
         }

260846-image.png


260867-image.png



image.png (14.1 KiB)
image.png (12.1 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

You did NOT follow the recommendations!

I've put the break point to [HttpPost] and I obtained : PRimaryKey ActionId= 0 and the ForeignKey CurrentActionId = 0

A zero means the client code, which we cannot see, did not populate an ActionId or CurrentActionId. Unfortunately, the renamed ActionItem class looks nothing like the ActionList class and I assume ActionItem is a new class altogether. However, the CurrentActionId (FK) should have a value passed from the caller. It is not clear why this is not happening.

The code or requirements have changed significantly since the initial post and you made no attempt to explain these changes. There's not much we can do to help you.


[1]: https://learn.microsoft.com/en-us/ef/core/saving/related-data





0 Votes 0 ·
sblb-6958 avatar image
0 Votes"
sblb-6958 answered AgaveJoe edited

I tried to follow up but I don't understand clear.
plus in your link there is a github link with the sample. Here RelatedData

I try to do the same class model but w/o succes.
Can you help me on it?

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I tried to follow up but I don't understand clear.

It is very clear that you do not understand. The problem I'm having is the code and question changes with each post. It's not clear what rabbit hole you're currently going down.

plus in your link there is a github link with the sample. Here RelatedData I try to do the same class model but w/o succes.

I'm not sure what you've tried.

Can you help me on it?

Maybe another forum member can help unravel what you're asking. It seems to me, at least originally, you were having trouble populating a C# type that contains a collection. Later it seems you are having trouble editing an item which also involves populating a C# type.

0 Votes 0 ·

I applied your recommendation and it doesn't work. Have you another example?

0 Votes 0 ·

I applied your recommendation and it doesn't work.

Where's the code?

Can you share the Web API action that has the DeveloperId route parameter and the List<ActionItem> parameter. Also, share where you are following the pattern shown in the Saving Related Data document. If you changed your mind and want to add a single ActionItem to a Developer then show this action.

Have you another example?

I don't. I need you to explain how the new ActionItem type works. The old ActionList, which I thought you renamed to ActionItem, had a developer Id foreign key. The new ActionItem has CurrentActionId foreign key and there no CurrentAction schema or model that I can see.




0 Votes 0 ·
sblb-6958 avatar image
0 Votes"
sblb-6958 answered sblb-6958 published

If you changed your mind and want to add a single ActionItem to a Developer then show this action.

I don't change ; I want several ACtionItem for one Developer row so the method one-to-many seems appropriate.

share where you are following the pattern shown in the Saving Related Data

here [related-data][1]

Class model Developer and ActionItem

public partial class Developer
{
public int Id { get; set; }
public List<ActionItem>? ActionItems { get; set; }
}

public class ActionItem
{
[Key]
public int ActionId { get; set; }
public string? Tilte { get; set; }
public string? Description { get; set; }
public string? State { get; set; }
public DateTime? OpenDate { get; set; }
public DateTime? PlanDate { get; set; }
public DateTime? CloseDate { get; set; }

public int Id { get; set; }
public Developer? Developer { get; set; }
}

The column DeveloperId is created in table ActionItem, see below initial migration

constraints: table =>
{
table.PrimaryKey("PK_ActionItems", x => x.ActionId);
table.ForeignKey(
name: "FK_ActionItems_Developers_DeveloperId",
column: x => x.DeveloperId,
principalTable: "Developers",
principalColumn: "Id");
});


[1]: https://learn.microsoft.com/en-us/ef/core/saving/related-data#adding-a-related-entity

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

sblb-6958 avatar image
0 Votes"
sblb-6958 answered sblb-6958 commented

Thanks to your proposition.
But it's doesn't work.

I don't obtain e.g Developer row (id=1) with several actions in page edit.

In your class model you use DeveloperId inn my side I use Id for two class.

In edit page in @code I call the post method as below :

  async Task CreateActionList()
     {        
         await http.PostAsJsonAsync("api/developeractions", act);
         uriHelper.NavigateTo($"/developer/edit/{developerId}");
     }

Have you an idea why I didn't populate the ActionITem?

I have also the developercontroller


     [HttpGet]
     public async Task<IActionResult> Get()
     {
         var devs = await _context.Developers.ToListAsync();
         return Ok(devs);
     }

     [HttpGet("{id}")]
     public async Task<IActionResult> Get(int id)
     {
         var dev = await _context.Developers.FirstOrDefaultAsync(a => a.Id == id);
         return Ok(dev);
     }       

     //Take a number ECO
     [HttpGet("GenearteEcoById/{id}")]
     public async Task<ActionResult<Developer>> GenearteEcoById(int id)
     {
         var developer = await _context.Developers.FindAsync(id);
         if (developer == null)
         {
             return NotFound();
         }
         if (developer.ECOYear == 0 && developer.ECOCount == 0 && developer.ECOSelected==true)
         {
             var values = await GenerateEcoByIdAsync(id);
             developer.ECOYear = values.Year;
             developer.ECOCount = values.Count;
             await _context.SaveChangesAsync();
         }
         else if(developer.ECOSelected == false)
         {
             developer.ECOYear = 0;
             developer.ECOCount = 0;
             await _context.SaveChangesAsync();

         }

         return developer;
     }
        
     private async Task<YearCount> GenerateEcoByIdAsync(int id)
     {
         if (!await _context.Developers.AnyAsync(d => d.ECOYear == DateTime.Now.Year))
         {
             return new YearCount() { Count = 1, Year = DateTime.Now.Year };
         }

         int max = await _context.Developers.Where(d => d.ECOYear == DateTime.Now.Year).MaxAsync(d => d.ECOCount) + 1;
         return new YearCount() { Count = max, Year = DateTime.Now.Year };
     }

     //Creates a new Developer with the passed developer object data AND take ECR Number
     [HttpPost]
     public async Task<IActionResult> Post(Developer developer)
     {
                   
         YearCount dev = await IncrementDeveloperIdAsync();

         developer.Year = dev.Year;
         developer.Count = dev.Count;

         _context.Add(developer);
         await _context.SaveChangesAsync();
         return Ok(developer.Id);
     }      
       
     //Take the number ECR
     private async Task<YearCount> IncrementDeveloperIdAsync()
     {
         if (!await _context.Developers.AnyAsync(d => d.Year == DateTime.Now.Year))
         {
             return new YearCount() { Count = 1, Year = DateTime.Now.Year };
         }

         int max = await _context.Developers.Where(d => d.Year == DateTime.Now.Year).MaxAsync(d => d.Count) + 1;
         return new YearCount() { Count = max, Year = DateTime.Now.Year };
     }

     //Modifies an existing developer record.
     [HttpPut]
     public async Task<IActionResult> Put(Developer developer)
     {
         _context.Entry(developer).State = EntityState.Modified;
         await _context.SaveChangesAsync();
         return NoContent();
     }

     [HttpDelete("{id}")]
     public async Task<IActionResult> Delete(int id)
     {
         var dev = new Developer { Id = id };
         _context.Remove(dev);
         await _context.SaveChangesAsync();
         return NoContent();
     }


· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

But it's doesn't work.

Works perfectly on my end. You must be doing something wrong.

I don't obtain e.g Developer row (id=1) with several actions in page edit.

you really need to learn how to troubleshoot your code. If you're updating an ActionItem and the ActionItemId is unique then you should be able to update that specific record by Id. If the record is not updating then, most likely, there is a problem with the code that populates the "act" type. Set a breakpoint and view the property values to make sure the code is setting the DeveloperId, ActionItemId, and any other fields that are required to properly update the record.

In your class model you use DeveloperId inn my side I use Id for two class.

Confused! I used your schema and your schema has a DeveloperId as a foreign key in ActionItem and DeveloperId is a primary key in Developer. If there is another class with a developed, that's fantastic but how does the other class have anything to do with the only two classes you've shared on the forum?


Have you an idea why I didn't populate the ActionITem?

There are bugs in your code and/or design. Have you tried using swagger to test the action? If the action is working as expected then the problem is with the code that sends the request.


You are not a new developer. Run your code through the Visual Studio debugger to find where the code stops working as expected.

Unfortunately, the controller you posted has nothing to do with ActionItem?!!!! What are you doing????

0 Votes 0 ·

Unfortunately, the controller you posted has nothing to do with ActionItem?!!!! What are you doing????

I ve two controllers Developer Controller and developeractionscontroller. The last controller is like you except key's name.
In developer class I use the Id
In actionsitem class I use the actionid



0 Votes 0 ·

In actionsitem class I use the actionid

I create a action to add an ActiobnItem and it just works.

 // POST api/<DeveloperActionController>/AddAction
 [HttpPost("/api/DeveloperAction/AddActionItem")]
 public async Task<ActionResult<Developer>> PostActionItem([FromBody] ActionItem actionItem)
 {
     _context.ActionItems.Add(actionItem);
     await _context.SaveChangesAsync();
    
     return CreatedAtAction(nameof(GetDeveloperActions), new { id = actionItem.DeveloperId }, actionItem);
 }

The payload is the same as I posted above.

 {
   "actionItemId": 0,
   "tilte": "Action Title 2",
   "description": "Description 2",
   "state": "State 2",
   "openDate": "2022-11-18",
   "planDate": "2022-11-18",
   "closeDate": "2022-11-18",
   "developerId": 1
 }


For the fourth time! Most likely the error is in the Blazor Application making the call. You have a lot of experience and should be able to single step through the code to find the bugs. Use swagger, which comes default in Web API, to test the action. If the action is able to add the ActionItem then clearly the issue is elsewhere. Most likely the client making the HTTP call which is the Blazor application has problems.

I'm not sure what else I can do for you.

0 Votes 0 ·
Show more comments
sblb-6958 avatar image
0 Votes"
sblb-6958 answered

I've made any corection for moment
You right there is status 400 in dev tools.

Also I've this message in devtools. I don't understand because I am in edit mode and this field is not required only in create mode

262108-image.png



image.png (24.2 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

sblb-6958 avatar image
0 Votes"
sblb-6958 answered AgaveJoe edited

I have removed the [required] annotations and I no longer have an error.
However, the ActionItem table is still not filled.

When I'm in the developer/edit mode I want to add an action; and surprise I add a line in developer. really I don't understand!

in address : https://localhost:44354/developer/edit/8 I added the button to add the actions.
When I validate the create button I create a row in developer while I want to create an action for the developer/edit/8

262203-image.png



image.png (59.9 KiB)
· 8
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Seriously?! For over five days the browser's dev tools reported an error and you did not bother to look? It takes a few seconds to open dev tools. I get the feeling your effort is lacking a bit.

I've already explained how to troubleshoot the code. Use the Swagger tool to debug the Web API actions. Once you have the Web API actions working as expected then use the network view in the browser's dev tools to verify the Blazor application is sending a proper JSON payload.

This is basic programming. Troubleshoot and fix your code.

0 Votes 0 ·

result of the devtool
A s you can see I can write in Action but it is not post in ActionItem.
Plus the action is created in Developer table not in page edit/8

![262286-image.png][1]

![262264-image.png][2]

I think it's a route problem

se the Swagger tool to debug the Web API actions.

Swagger does not working. my app is blazor wasm core .net6.


[1]: /answers/storage/attachments/262286-image.png
[2]: /answers/storage/attachments/262264-image.png
0 Votes 0 ·
image.png (19.4 KiB)

As you can see I can write in Action but is not post in ActionItem.

The last URL you shared goes to the developer controller not an ActionItem controller.

 https://localhost:44354/developer/edit/8

If you want to call the ActionItem controller then change the URL.

Swagger does not working. my app is blazor wasm core .net6.

Nonsense. Swagger comes default with the Web API template and you're clearly calling Web API. If you need to add Swagger then it is two lines of code!

You have a lot of experience on these forums and I've provided this type of advice over several months. It seems you simply do not have the skills and you're not trying to move forward. I'm not sure how to help you.

0 Votes 0 ·
Show more comments
sblb-6958 avatar image
0 Votes"
sblb-6958 answered AgaveJoe edited

When I put a breakpoint in POST api/<DeveloperActionController> I can see that ACtionsItem is null

262632-image.png

But I see in devtools the ActionItem is fill but it does not populate when it's validated

262560-image.png


I am missing something !!


image.png (15.7 KiB)
image.png (18.1 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

The "Id" property is zero! The design tries to assign an ActionItem to developer zero.

I provided two different patterns with payload examples for saving related data but you refused the solutions in favor of your approach which does not work.

0 Votes 0 ·