Currently I've got this:
AddEvent.cshtml
@model Evenementor.Models.EvenementorEvent
@{
ViewBag.Title = "Voeg een evenement toe";
}
@using (Html.BeginForm(new { ReturnUrl = ViewBag.ReturnUrl }))
{
<div class="12u">
@Html.TextBoxFor(m => m.Title, new { @placeholder = "Titel" })
</div>
<div class="12u">
@Html.TextAreaFor(m => m.Description, new { @placeholder = "Omschrijving" })
</div>
<div class="6u">
@Html.TextBoxFor(m => m.Startdate, new { @placeholder = "Startdag" })
</div>
<div class="6u">
@Html.TextBoxFor(m => m.Enddate, new { @placeholder = "Einddag" })
</div>
<div class="12u">
@Html.TextBoxFor(m => m.Location, new { @placeholder = "Locatie" })
</div>
<div class="12u">
<select name="Type">
@foreach (var item in ViewData["Types"] as List<Evenementor.Models.EvenementorType>)
{
<option value="@item.TypeID">@item.Name</option>
}
</select>
</div>
<input type="submit" value="Voeg toe" />
}
DashboardController.cs
// GET: /Dashboard/AddEvent
public ActionResult AddEvent()
{
if (!User.Identity.IsAuthenticated)
{
// User isn't allowed here
Response.Redirect("/");
}
ViewData["Types"] = EvenementorType.GetAllTypes();
return View();
}
// POST: /Dashboard/AddEvent
[HttpPost]
public ActionResult AddEvent(EvenementorEvent ev)
{
if (!User.Identity.IsAuthenticated)
{
// User isn't allowed here
Response.Redirect("/");
}
if (ModelState.IsValid)
{
EvenementorEvent e = new EvenementorEvent();
e.Title = ev.Title;
e.Description = ev.Description;
e.Startdate = ev.Startdate;
e.Enddate = ev.Enddate;
e.Location = ev.Location;
// Register the event
e.Register(e);
// Make a link between event and organisation
EvenementorOrganisationsEvent l = new EvenementorOrganisationsEvent();
l.EventID = e.EventID;
l.OrganisationID = EvenementorOrganisation.GetOrganisationByEmail(User.Identity.Name).OrganisationID;
l.Register(l);
// Link between event and type
EvenementorEventsType ty = new EvenementorEventsType();
ty.EventID = e.EventID;
//GET THE OTHER INFO (Types)
// Redirect
Response.Redirect("/Dashboard/");
}
// Something's wrong!
return View(ev);
}
How can I get the data from the input from the dropdown back into my controller? Or is there any other/better solution to this?
Thanks in advance, I'm a total newb to ASP.NET. Still learning on my own.