morry329#
morry329#
CC#
Created by morry329# on 12/23/2024 in #help
Unable to create an object of type 'JsonContext'
So I removed parameterless JsonContext() with Database.EnsureCreated(). Those were replaced with
public JsonContext(DbContextOptions<JsonContext> options)
: base(options)
{
}
public JsonContext(DbContextOptions<JsonContext> options)
: base(options)
{
}
but the error persists (Unable to create an object of type 'JsonContext'. For the different patterns supported at design time, see `https://go.microsoft.com/fwlink/?linkid=851728) No idea what triggerd this error. Do you have any idea?
8 replies
CC#
Created by morry329# on 12/19/2024 in #help
Edit view directs to 404 not found
so can we assume that this app cannot find that controller (not Homecontroller), which leads to 404?
6 replies
CC#
Created by morry329# on 12/19/2024 in #help
Edit view directs to 404 not found
if I am not mistaken
6 replies
CC#
Created by morry329# on 12/19/2024 in #help
Edit view directs to 404 not found
No, Home is the only controller here
6 replies
CC#
Created by morry329# on 12/1/2024 in #help
Edit function does not work
public IActionResult Update(ListingProjects updatedUserModelRef)
{
var oldListing = _context.ListingDBTable.FirstOrDefault(e => e.Id == updatedUserModelRef.Id);
if (oldListing == null)
{
// Handle the case where no record is found (e.g., return an error message)
return NotFound(); // Assuming you have a NotFound action
}
_context.Entry(oldListing).CurrentValues.SetValues(updatedUserModelRef);
_context.SaveChanges();
return RedirectToAction("TestDashboard1");
}
public IActionResult Update(ListingProjects updatedUserModelRef)
{
var oldListing = _context.ListingDBTable.FirstOrDefault(e => e.Id == updatedUserModelRef.Id);
if (oldListing == null)
{
// Handle the case where no record is found (e.g., return an error message)
return NotFound(); // Assuming you have a NotFound action
}
_context.Entry(oldListing).CurrentValues.SetValues(updatedUserModelRef);
_context.SaveChanges();
return RedirectToAction("TestDashboard1");
}
` I rewrote the code like this. does the database model leave the "boundary" with this snippet too?
20 replies
CC#
Created by morry329# on 12/1/2024 in #help
Edit function does not work
Can you also help me understand why my database model left the application's boundary? I just would like more clarity in that
20 replies
CC#
Created by morry329# on 12/1/2024 in #help
Edit function does not work
Can you help me understand why my code submitted this data? I mean this
public class ListingProject
{
public int Id { get; set; }
public string ListingName { get; set; }
public string __RequestVerificationToken { get; set; }
}
public class ListingProject
{
public int Id { get; set; }
public string ListingName { get; set; }
public string __RequestVerificationToken { get; set; }
}
` Not this
public class ListingProjects
{
[Key]
public int? Id { get; set; } // Primary key

[Required]
public string? ListingName { get; set; }

[Required]
public string? ImageUrl { get; set; }

[Required]
public int? CategoryId { get; set; }
public Category? Category { get; set; }

[Required]
public int? LocationId { get; set; }
public Location? Location { get; set; }

public ListingProjectsDTO? ListingProjectsDTO { get; set; } // Navigation property
}
public class ListingProjects
{
[Key]
public int? Id { get; set; } // Primary key

[Required]
public string? ListingName { get; set; }

[Required]
public string? ImageUrl { get; set; }

[Required]
public int? CategoryId { get; set; }
public Category? Category { get; set; }

[Required]
public int? LocationId { get; set; }
public Location? Location { get; set; }

public ListingProjectsDTO? ListingProjectsDTO { get; set; } // Navigation property
}
`
20 replies
CC#
Created by morry329# on 12/1/2024 in #help
Edit function does not work
Not at all In my IDE the ListingProject has properties as follows
public class ListingProjects
{
[Key]
public int? Id { get; set; } // Primary key

[Required]
public string? ListingName { get; set; }

[Required]
public string? ImageUrl { get; set; }

[Required]
public int? CategoryId { get; set; }
public Category? Category { get; set; }

[Required]
public int? LocationId { get; set; }
public Location? Location { get; set; }

public ListingProjectsDTO? ListingProjectsDTO { get; set; } // Navigation property
}
public class ListingProjects
{
[Key]
public int? Id { get; set; } // Primary key

[Required]
public string? ListingName { get; set; }

[Required]
public string? ImageUrl { get; set; }

[Required]
public int? CategoryId { get; set; }
public Category? Category { get; set; }

[Required]
public int? LocationId { get; set; }
public Location? Location { get; set; }

public ListingProjectsDTO? ListingProjectsDTO { get; set; } // Navigation property
}
it is strange for me that my app thinks my listingProject class looks like that public class ListingProject { public int Id { get; set; } public string ListingName { get; set; } public string __RequestVerificationToken { get; set; } }` I have no idea why. Do you have idea?
20 replies
CC#
Created by morry329# on 11/8/2024 in #help
Save button does not save the inserted data
I just got rid of all the IEnumerable implementation, then the exception is gone. ChatGPT recommended me to make the ListingProjects enumerable (as I wanted to make a collection of vacation listing names) But now for the sake of simplicity I will learn more about IEnumerable, this one caused me some unwanted exception
15 replies
CC#
Created by morry329# on 11/8/2024 in #help
Save button does not save the inserted data
ups, I did not want to return all the records from the table .. see, I did not understand what my code is doing. so with this line return await _context.ListingDBTable.ToListAsync(); it will return all records from the table, correct? And it eventually triggers the exception as it causes the circulation or
15 replies
CC#
Created by morry329# on 11/8/2024 in #help
Save button does not save the inserted data
Network tab just got me this https://pastebin.com/stiTYN5g This exception seems to point to
[HttpGet("availableListings")]
public async Task<IEnumerable<ListingProjects>> Get()
{
return await _context.ListingDBTable.ToListAsync();
}
[HttpGet("availableListings")]
public async Task<IEnumerable<ListingProjects>> Get()
{
return await _context.ListingDBTable.ToListAsync();
}
` This method is in the API controller class separately created from HomeController (where this save method lies) : you can find the full code for the API controller https://pastebin.com/f73x8fDN I tried something like this on Program.cs
builder.Services.AddControllersWithViews().AddJsonOptions(options =>
{
options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.Preserve;
options.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
});
builder.Services.AddControllersWithViews().AddJsonOptions(options =>
{
options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.Preserve;
options.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
});
` But the exception is not gone I suppose this exception prevents my code from what it should be doing
15 replies
CC#
Created by morry329# on 11/3/2024 in #help
Does this make sense? |
Ok so it does not make sense then. I do not ask for the solution code or anything but I would like some advice on how to approach it: I googled how to delete the card view with the button Onclick: I only found the frontend ways like manipulating jquery to make the div items disappear (that div has no text data retrieved/loaded from SQL). If the div card item displays data loaded from SQL, does it still make sense to remove it via jquery etc? Or would you do that very differently?
5 replies
CC#
Created by morry329# on 10/7/2024 in #help
Not found 404 at await fetch
No description
6 replies
CC#
Created by morry329# on 10/7/2024 in #help
Not found 404 at await fetch
Hi! So I tried like this await fetch('/api/APIController/availableListing') Unfortunately the 404 error stays as per screenshot attached What could cause this? Maybe the API controller did trigger this 404?
6 replies
CC#
Created by morry329# on 9/30/2024 in #help
Does it make sense to two references (to database migration and data seeding) in the same using
Thank you so much for the detailed explanation 🙏 I will remove the services line then
6 replies
CC#
Created by morry329# on 9/24/2024 in #help
created a new view but that view only outputs the html (of the login page!)
well this innovative idea came from AI, ofc not from me. No idea what kind of company needs an app like this, returning HTML instead of JSON :kekw: I ended up adding this line return Redirect(requestUrl) I hope this is what you meant
23 replies
CC#
Created by morry329# on 9/24/2024 in #help
created a new view but that view only outputs the html (of the login page!)
Ahh ok ContentType = "application/json", So my uneducated guess is: if I keep application/json like this the app will display the bunch of HTML on the browser, right? I assume changing this would do the trick
23 replies
CC#
Created by morry329# on 9/24/2024 in #help
created a new view but that view only outputs the html (of the login page!)
Please bear with me asking this stupid question: what is the mime type you are referring to?
23 replies
CC#
Created by morry329# on 9/24/2024 in #help
created a new view but that view only outputs the html (of the login page!)
it's just everything was so new to me that I have no idea where I was fetching the HTML from
23 replies
CC#
Created by morry329# on 9/24/2024 in #help
created a new view but that view only outputs the html (of the login page!)
I see, thank you so much for helping me understand this code. I am very new to this. Could you give me some hint to await that properly (or do you have some links)?
23 replies