BlasterBlaster
BlasterBlaster
CC#
Created by BlasterBlaster on 11/30/2023 in #help
ASP.NET MVC
aswell
53 replies
CC#
Created by BlasterBlaster on 11/30/2023 in #help
ASP.NET MVC
I think my ViewModel is formatted wrong for what I want for my game to work
53 replies
CC#
Created by BlasterBlaster on 11/30/2023 in #help
ASP.NET MVC
But this is very difficult for me
53 replies
CC#
Created by BlasterBlaster on 11/30/2023 in #help
ASP.NET MVC
I think it is how i coded my view
53 replies
CC#
Created by BlasterBlaster on 11/30/2023 in #help
ASP.NET MVC
But my current issue is now my data is not being passed correctly to my controller
53 replies
CC#
Created by BlasterBlaster on 11/30/2023 in #help
ASP.NET MVC
Ok well I've made progress
53 replies
CC#
Created by BlasterBlaster on 11/30/2023 in #help
ASP.NET MVC
I want it to send my viewmodel to my post
53 replies
CC#
Created by BlasterBlaster on 11/30/2023 in #help
ASP.NET MVC
One thing is that my ModelState.IsValid is returning false, and I don't know why this is.
53 replies
CC#
Created by BlasterBlaster on 11/30/2023 in #help
ASP.NET MVC
Saying it can't find a save view
53 replies
CC#
Created by BlasterBlaster on 11/30/2023 in #help
ASP.NET MVC
If I switch my asp-action="Save" in my view then it will crash on submitting
53 replies
CC#
Created by BlasterBlaster on 11/30/2023 in #help
ASP.NET MVC
I am not able to transfer my data to the controller
53 replies
CC#
Created by BlasterBlaster on 11/30/2023 in #help
ASP.NET MVC
I don't understand how the form is submitting
53 replies
CC#
Created by BlasterBlaster on 11/30/2023 in #help
ASP.NET MVC
This is my website
53 replies
CC#
Created by BlasterBlaster on 11/30/2023 in #help
ASP.NET MVC
No description
53 replies
CC#
Created by BlasterBlaster on 11/30/2023 in #help
ASP.NET MVC
@model GameViewModel


<div class="text-center">
<h1 class="display-4">Welcome</h1>

</div>
<form asp-controller="Game" asp-action="Save" method="post">
<div asp-validation-summary="All" class="text-danger"></div>

@foreach(var question in Model.Questions)
{
<div class="form-group">
<label>@question.Species</label>
<input name="GameViewModel.UserInput" class="form-control" type="text" placeholder="@question.Species is a type of...">
<input type="hidden" name="GameViewModel.Questions.Genus" value="@question.Genus">
</div>
}
<button type="submit">Submit</button>
</form>
@model GameViewModel


<div class="text-center">
<h1 class="display-4">Welcome</h1>

</div>
<form asp-controller="Game" asp-action="Save" method="post">
<div asp-validation-summary="All" class="text-danger"></div>

@foreach(var question in Model.Questions)
{
<div class="form-group">
<label>@question.Species</label>
<input name="GameViewModel.UserInput" class="form-control" type="text" placeholder="@question.Species is a type of...">
<input type="hidden" name="GameViewModel.Questions.Genus" value="@question.Genus">
</div>
}
<button type="submit">Submit</button>
</form>
This is my view
53 replies
CC#
Created by BlasterBlaster on 11/30/2023 in #help
ASP.NET MVC
using FinalProject.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;

namespace FinalProject.Controllers
{
public class GameController : Controller
{
private FinalProjectContext _context;
public GameController(FinalProjectContext context)
{
_context = context;
}

public IActionResult Index()
{
List<Question> questions = _context.Questions.ToList();
GameViewModel gameViewModel = new GameViewModel();
gameViewModel.Questions = questions;
return View(gameViewModel);
}


[HttpPost]
public IActionResult Save(GameViewModel gameViewModel)
{

if (ModelState.IsValid)
{
foreach (Question question in gameViewModel.Questions)
{
//if (question.Genus != gameViewModel.UserInput)
// ModelState.AddModelError("", question.Species + " is wrong!");
string test = "Genus is " + question.Genus + " input is " + gameViewModel.UserInput;

}
return RedirectToAction("Index", "Home");
}
else
{
return View(gameViewModel);
}


}



}
}
using FinalProject.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;

namespace FinalProject.Controllers
{
public class GameController : Controller
{
private FinalProjectContext _context;
public GameController(FinalProjectContext context)
{
_context = context;
}

public IActionResult Index()
{
List<Question> questions = _context.Questions.ToList();
GameViewModel gameViewModel = new GameViewModel();
gameViewModel.Questions = questions;
return View(gameViewModel);
}


[HttpPost]
public IActionResult Save(GameViewModel gameViewModel)
{

if (ModelState.IsValid)
{
foreach (Question question in gameViewModel.Questions)
{
//if (question.Genus != gameViewModel.UserInput)
// ModelState.AddModelError("", question.Species + " is wrong!");
string test = "Genus is " + question.Genus + " input is " + gameViewModel.UserInput;

}
return RedirectToAction("Index", "Home");
}
else
{
return View(gameViewModel);
}


}



}
}
This is my controller
53 replies
CC#
Created by BlasterBlaster on 11/30/2023 in #help
ASP.NET MVC
I am still having issues with my program.
53 replies
CC#
Created by BlasterBlaster on 11/30/2023 in #help
ASP.NET MVC
Going to bump my thread to see if anyone can help me.
53 replies
CC#
Created by BlasterBlaster on 11/30/2023 in #help
ASP.NET MVC
Okay, I don't know Javascript haha so maybe just use a button
53 replies
CC#
Created by BlasterBlaster on 11/30/2023 in #help
ASP.NET MVC
One more thing, can I use the "Enter" button to submit my <input> or do I need to connect a button to it?
53 replies