C
C#10mo ago
Eren

Gamelog not working

I had to create a game trough a mvc controller and the gamelog isnt logging my details
No description
67 Replies
SinFluxx
SinFluxx10mo ago
$details
MODiX
MODiX10mo ago
When you ask a question, make sure you include as much detail as possible. Such as code, the issue you are facing, and what you expect the result to be. Upload code here https://paste.mod.gg/ (see $code for more information on how to paste your code)
Eren
ErenOP10mo ago
it should look like this
Eren
ErenOP10mo ago
No description
No description
No description
Eren
ErenOP10mo ago
$code
MODiX
MODiX10mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
Eren
ErenOP10mo ago
@model PRG.EVA01.SeaBattle.Models.GameLog

@{
ViewData["Title"] = "Details";
}

<h1>Details</h1>

<div>
<h4>GameLog</h4>
<hr />
<dl class="row">
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.GameId)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.GameId)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.PlayerName)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.PlayerName)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.LocationLetter)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.LocationLetter)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.LocationNumber)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.LocationNumber)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.Result)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.Result)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.CreatedOn)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.CreatedOn)
</dd>
</dl>
</div>
<div>
<a asp-action="Edit" asp-route-id="@Model?.Id">Edit</a> |
<a asp-action="Index">Back to List</a>
</div>
@model PRG.EVA01.SeaBattle.Models.GameLog

@{
ViewData["Title"] = "Details";
}

<h1>Details</h1>

<div>
<h4>GameLog</h4>
<hr />
<dl class="row">
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.GameId)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.GameId)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.PlayerName)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.PlayerName)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.LocationLetter)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.LocationLetter)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.LocationNumber)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.LocationNumber)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.Result)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.Result)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.CreatedOn)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.CreatedOn)
</dd>
</dl>
</div>
<div>
<a asp-action="Edit" asp-route-id="@Model?.Id">Edit</a> |
<a asp-action="Index">Back to List</a>
</div>
this is my details view is there something wrong here that is making it not show the details
Pobiega
Pobiega10mo ago
are you sure there is any data being passed to the view? set a breakpoint in the controller action before you invoke the view
Eren
ErenOP10mo ago
where is this sorry if im asking a dumb question i had to create a database which i did then trough nuggets create the tables and that also worked now showing me the screen at the top if u also need this info just incase
Pobiega
Pobiega10mo ago
so in MVC you have three components Model, View, Controller I want you to go into the controller and show us the code
Eren
ErenOP10mo ago
oh alright ill send it right now its saying the code is to long to send in here too many characters
MODiX
MODiX10mo ago
MODiX#0152
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
Quoted by
<@105026391237480448> from #Gamelog not working (click here)
React with ❌ to remove this embed.
Eren
ErenOP10mo ago
do i send u the link now?
Pobiega
Pobiega10mo ago
yes.
Eren
ErenOP10mo ago
file:///C:/Users/erena/Downloads/BlazeBin.html
Eren
ErenOP10mo ago
BlazeBin
A tool for sharing your source code with the world!
Eren
ErenOP10mo ago
does this work?
Eren
ErenOP10mo ago
BlazeBin - iuvcnetsxggi
A tool for sharing your source code with the world!
Eren
ErenOP10mo ago
idk which link is correct here
Pobiega
Pobiega10mo ago
The last one. And uh... how is that not obvious? I genuinely ask.
Eren
ErenOP10mo ago
oh okay so u see what the issue is or as in the break point position u mentioned
Pobiega
Pobiega10mo ago
The first is the path to a file on your computer. the second is just "paste.mod.gg" the third one has some form of unique ID in it
Eren
ErenOP10mo ago
yh just asking to make sure my bad
Pobiega
Pobiega10mo ago
I think thats the wrong controller?
Eren
ErenOP10mo ago
i also have created another controller for the gamelogs let me send this in too maybe thats what is needed here to look at
Pobiega
Pobiega10mo ago
Look. You paste an image of the GameLogs view empty and you send me the code for an unrelated controller Come on!
Eren
ErenOP10mo ago
sorry
Eren
ErenOP10mo ago
BlazeBin - jqqoddmzeinb
A tool for sharing your source code with the world!
Eren
ErenOP10mo ago
this is the other controller that is related to gamelogs
Pobiega
Pobiega10mo ago
okay so what we are looking at is
public async Task<IActionResult> Index()
{
return View(await _context.GameLogs.ToListAsync());
}
public async Task<IActionResult> Index()
{
return View(await _context.GameLogs.ToListAsync());
}
thats the action that calls the view you showed
Eren
ErenOP10mo ago
yeah
Pobiega
Pobiega10mo ago
lets separate that into two calls, so we can inspect the variable var gamelogs = await _context... then return View(gamelogs);
Eren
ErenOP10mo ago
okay so i will change that real quick so u have the gamelogs awaiting context then the view returns the gamelogs
Pobiega
Pobiega10mo ago
its the exact same code as you already have just broken up into two lines
Eren
ErenOP10mo ago
yeah just seperated
Pobiega
Pobiega10mo ago
ye and then I want you to set a breakpoint on the second line, the return one
Eren
ErenOP10mo ago
okay ill change it to that real quick and set the breakpoint done
Pobiega
Pobiega10mo ago
okay, and the breakpoint is set?
Eren
ErenOP10mo ago
yes but when i click f11 it doesnt bring me to it
Pobiega
Pobiega10mo ago
thats... uh... what start the program, open your gamelogs page that should hit the breakpoint
Eren
ErenOP10mo ago
it did yes
Eren
ErenOP10mo ago
this is what its showing rn
No description
Eren
ErenOP10mo ago
sorry if screenshots are annoying
Pobiega
Pobiega10mo ago
No description
Pobiega
Pobiega10mo ago
count = 0 your database contains no game log entries
Eren
ErenOP10mo ago
so its counting nothing indeed
Pobiega
Pobiega10mo ago
so yeah, no data is showing because you have no data
Eren
ErenOP10mo ago
right and retrieving data will be done how exactly
Pobiega
Pobiega10mo ago
what do you mean?
Eren
ErenOP10mo ago
because we need to type in a specific location which is the url and then it will say hit miss or invalid location which should be the log of the game
Pobiega
Pobiega10mo ago
so you're making the game Battleships?
Eren
ErenOP10mo ago
seabattle yeah
Pobiega
Pobiega10mo ago
await _context.GameLogs.ToListAsync(); this is the code that fetches all your logs from the database all of them but your database currently doesnt contain any
Eren
ErenOP10mo ago
right so do i need to add it because it should just retrieve the data when a player does something but its not
Pobiega
Pobiega10mo ago
uh are you mixing up the word "retrieve" and "add"? retrieve is to fetch something you already do that
Eren
ErenOP10mo ago
let me show u what i mean cuz im wording it wrong
Pobiega
Pobiega10mo ago
Go ahead, but I'm gonna go to bed.
Eren
ErenOP10mo ago
so this is the result
No description
Eren
ErenOP10mo ago
then it should log that it was a miss for example oh alr goodnight
Pobiega
Pobiega10mo ago
your code for ThrowBomb doesnt add anything to the logs database in fact, it doesnt write anything to anywhere it just updates the ViewBag 3 times. Please don't use the viewbag 😦
Eren
ErenOP10mo ago
i have no idea else how to do it so what do i need to adjust for it to do that then
Pobiega
Pobiega10mo ago
Add something to the database?
Eren
ErenOP10mo ago
do i need to do that trough sql? because in the project they dont tell us to ever do that hence why im confused why its not working maybe another nugget command
Jimmacle
Jimmacle10mo ago
well, you can't get something from the database that you didn't put in
Pobiega
Pobiega10mo ago
_context.GameLogs.Add(...) and then await _context.SaveChangesAsync(); but you need to figure out what to add and where
Eren
ErenOP10mo ago
exactly my point but i dont understand why they never mention putting something in yeah is that missing in my code?
Pobiega
Pobiega10mo ago
.. yes? I don't really understand how that isn't obvious Your code has no mention of adding to the database at all - and you are wondering if that's why your database is empty?
Want results from more Discord servers?
Add your server