While trying to get the basic CRUD to work in my Web application I have run into some problems. I have managed to use
Html.Beginform("bla","bla", FormMethod.Get)
to correctly query string wanted data to a new view.
Photo evidence:

Now I have scoured the internet for tutorials, and the method to display said query string data in a form, and i have found nothing at all that helped me.
this is the view code of the page that I wish to fill and my ActionResults:
@using MvcApplication1.Models;
@model Klant
@{
ViewBag.Title = "ShowKlant";
}
<h2>ShowKlant</h2>
<div id="producetop" class="row">
@{ @*if (@Model == null)
{
<div>geen producten gevonden</div>
}
else
{*@
//foreach (Klant kl in Model)
//{
<div style="float: left">
<fieldset id="produce">
<form method="get">
<div><labe>ID: </labe><input type="hidden" name="id" value="@Html.Value("","")" /></div>
<div><label>Naam:</label> <input type="text" name="naam" value="" /></div>
<div><label>Woonplaats:</label> <input type="text" name="woonplaats" value="" /></div>
<div><label>Geboortedatum:</label> <input type="text" name="gebdat" value="" /></div>
<div><label>Geslacht:</label> <input type="text" name="geslacht" value="" /></div>
<div><label>Beschrijving:</label> <input type="text" name="beschrijving" value="" /></div>
</form>
</fieldset>
</div>
@*}*@
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
</div>
Actionresults:
public ActionResult ShowKlant()
{
return View();
}
[HttpPost]
public ActionResult ShowKlant(int? idklant)
{
Klant k = new Klant();
KlantDBController sc = new KlantDBController();
k = sc.getById(idklant);
return View(k);
}
Here is the view that 'pushes' the querystring:
@using MvcApplication1.Models;
@model List<Klant>
@{
ViewBag.Title = "ShowAllKlanten";
}
<h2>ShowAllKlanten</h2>
@using (Html.BeginForm("ShowKlant", "Home", FormMethod.Get, new { @enctype = "multipart/form-data" }))
{
if (@Model == null)
{
<div>geen producten gevonden</div>
}
else
{
<div></div><br>
foreach (Klant kl in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => kl.idklant)
</td>
<td>
@Html.DisplayFor(modelItem => kl.naam)
</td>
<td>
@Html.DisplayFor(modelItem => kl.woonplaats)
</td>
<td>
@Html.DisplayFor(modelItem => kl.geboortedatum)
</td>
<td>
@Html.DisplayFor(modelItem => kl.geslacht)
</td>
<td>
@Html.DisplayFor(modelItem => kl.beschrijving)
</td>
<td>
@Html.ActionLink("Details", "ShowKlant", new { id = kl.idklant, naam = kl.naam, woonplaats = kl.woonplaats, gebdat = kl.geboortedatum, geslacht = kl.geslacht, beschrijving = kl.beschrijving }) |
@Html.ActionLink("Edit", "ShowKlant", new { id = kl.idklant }) |
@Html.ActionLink("Delete", "ShowKlant", new { id = kl.idklant })<br /><br />
</td>
</tr>
I would appreciate a nudge in the right direction, because i am completely confused at the moment.
I am preemptively assuming that my action results are completely wrong, however i am unsure how to un-wrong them.
more context:
public class DatabaseController : Controller
{
protected MySqlConnection conn;
public DatabaseController()
{
//Vul hier de juiste gegevens in!!
conn = new MySqlConnection("Server=localhost;Database=dating;Uid=root;Pwd=root;");
}
}
SQL that loads my table:
public List<Klant> getAllKlanten(String naam)
{
MySqlTransaction trans = null;
List<Klant> klanten = new List<Klant>();
conn.Open();
trans = conn.BeginTransaction();
try
{
string selectQuery = @"select * from klant;";
MySqlCommand cmd = new MySqlCommand(selectQuery, conn);
//MySqlParameter naamParam = new MySqlParameter("@naam", MySqlDbType.VarChar);
//naamParam.Value = "%" + naam + "%";
//cmd.Parameters.Add(naamParam);
cmd.Prepare();
MySqlDataReader dataReader = cmd.ExecuteReader();
while (dataReader.Read())
{
Klant klant = new Klant();
klant.idklant = dataReader.GetInt32("idklant");
klant.naam = dataReader.GetString("naam");
klant.woonplaats = dataReader.GetString("woonplaats");
klant.geboortedatum = dataReader.GetDateTime("geboortedatum");
klant.geslacht = dataReader.GetString("geslacht");
klant.beschrijving = dataReader.GetString("beschrijving");
klanten.Add(klant);
Console.Write(klant.naam);
}
}
catch (Exception e)
{
throw new Exception("Product niet toegevoegd: " + e);
}
finally
{
conn.Close();
}
return klanten;
}
This is what my initial view looks like:

And this is what i am trying to fill with said querystring:

Photo evidence. What is it you are trying to do in the first place, - then I understand you've found some solution - but I don't know to what, and then what is the problem with the solution you've found ?!?KlantDBController sc = new KlantDBController();k = sc.getById(idklant);(1) Why have you mentioned Entity Framework (2) Where is your data, what kind of DB (3) Did you create aedmxfile (As in an EntityModel) for your data? (4) How or where that query string come from ? You seem to doing some basic things incorrectly and/or are on a very different plane of thinking. Have you looked at some basic asp-mvc examples?