我正在制作露营计划。客户可以在网站上进行预订,接待员可以接受并在客户到达时向客户提供更多信息(如护照号码)。
我的预订表如下:
[ID] INT IDENTITY (1, 1) NOT NULL,
[StartDatum] DATE NULL,
[EindDatum] DATE NULL,
[Plaats] VARCHAR (50) NULL,
[Status] VARCHAR (50) NULL,
[KlantID] INT NULL,
CONSTRAINT [FK_Reserveringen_ToTable] FOREIGN KEY ([KlantID]) REFERENCES [dbo].[Klants] ([Id])
我的客户表格如下:
[Id] INT IDENTITY (1, 1) NOT NULL,
[Voornaam] VARCHAR (50) NOT NULL,
[Achternaam] VARCHAR (50) NOT NULL,
[Adres] VARCHAR (50) NOT NULL,
[Postcode] VARCHAR (50) NULL,
[Plaats] VARCHAR (50) NULL,
[Telefoon] INT NOT NULL,
[Geboortedatum] INT NULL,
[Documentnr] INT NULL,
[Verificatiemiddel] VARCHAR (50) NULL,
[Emailadres] VARCHAR (50) NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
我为客户表和预订表制作了一个模型。
这就是我的观点在网站上进行预订的方式
@model Camping.Domain.Entities.Reservering
<div class="panel panel-success">
<div class="panel-heading text-center"><h4>RSVP</h4></div>
<div class="panel-body">
@using (Html.BeginForm("KlantToevoegen", "Klant", FormMethod.Post, new { enctype = "mulipart/formdata" }))
{
@Html.ValidationSummary()
<div class="form-group">
<label>Voornaam:</label>
@Html.TextBoxFor(x => x.Voornaam, new { @class = "form-control" })
</div>
<div class="form-group">
<label>Achternaam:</label>
@Html.TextBoxFor(x => x.Achternaam, new { @class = "form-control" })
</div>
<div class="form-group">
<label>Emailadres:</label>
@Html.TextBoxFor(x => x.Emailadres, new { @class = "form-control" })
</div>
<div class="form-group">
<label>Telefoonnummer:</label>
@Html.TextBoxFor(x => x.Telefoonnnummer, new { @class = "form-control" })
</div>
<div class="form-group">
<label>Datum aankomst:</label>
@Html.TextBoxFor(x => x.StartDatum, new { @class = "form-control" })
</div>
<div class="form-group">
<label>Datum vertrek:</label>
@Html.TextBoxFor(x => x.EindDatum, new { @class = "form-control" })
</div>
<div class="form-group">
<label>Plaats:</label>
@Html.TextBoxFor(x => x.Plaats, new { @class = "form-control" })
</div>
<div class="text-center">
<input class="btn btn-success" type="submit" value="Klant toevoegen" />
</div>
}
</div>
</div>
对于这个观点我做了一个模型。这是:
namespace Camping.Domain.Entities
{
public class Reservering
{
public string Voornaam { get; set; }
public string Achternaam { get; set; }
public int Telefoonnnummer { get; set; }
public string Emailadres { get; set; }
public string Plaats { get; set; }
public DateTime StartDatum { get; set; }
public DateTime EindDatum { get; set; }
}
}
控制器类:
using Camping.Domain.Abstract;
using Camping.Domain.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Camping.WebUII.Controllers
{
public class ReserveringController : Controller
{
private IRepository repository;
public ReserveringController(IRepository iRepository)
{
this.repository = iRepository;
}
[HttpGet]
public ViewResult ReserveringAanmaken()
{
return View();
}
[HttpPost]
public ActionResult Add(Reservering model)
{
var klant = new Klant
{
Voornaam = model.Voornaam,
Achternaam = model.Achternaam,
Emailadres = model.Emailadres,
Telefoon = model.Telefoonnnummer
};
var reservering = new Reserveringen
{
StartDatum = model.StartDatum,
EindDatum = model.EindDatum,
Plaats = model.Plaats
};
repository.KlantToevoegen(klant);
repository.ReserveringToevoegen(reservering);
return View();
}
}
}
此解决方案无法正常工作,出于某种原因,我感觉不对我正在做的事情。谁能指出我正确的方向?欲获得更多信息。随意问:)
当我通过视图添加日期时。我只填写客户表而不是预订表。
答案 0 :(得分:0)
您将视图中的字符串传递给控制器而不是日期时间