Asp.net MVC проверьте, является ли эта регистрация бесплатной или нет
Я новичок в этом деле asp.net mvc.Pleace помогите мне проверить, существует ли значение, которое я написал в своей базе данных.значение 4columns должно проверить и вернуть сообщение
Что я уже пробовал:
namespace poezd.Models { using System; using System.Collections.Generic; public partial class Reqistration { public int ID { get; set; } public string CustomerName { get; set; } public Nullable<int> PoezdID { get; set; } public Nullable<int> VaqonID { get; set; } public Nullable<int> MestoID { get; set; } public Nullable<System.DateTime> Date { get; set; } public virtual Poezd Poezd { get; set; } public virtual MestoVaqon MestoVaqon { get; set; } public virtual Vaqon Vaqon { get; set; } } }
мой класс reqistration(проверить, если VaqonID &амп;&амп; PoezdID &амп;&амп; MestoID &&усилителя; дата)уже существует.
@using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="form-horizontal"> <h4>Reqistration</h4> <hr /> @Html.ValidationSummary(true, "", new { @class = "text-danger" }) <div class="form-group"> @Html.LabelFor(model => model.CustomerName, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.CustomerName, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.CustomerName, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.PoezdID, "PoezdID", htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.DropDownList("PoezdID", null, htmlAttributes: new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.PoezdID, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.VaqonID, "VaqonID", htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.DropDownList("VaqonID", null, htmlAttributes: new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.VaqonID, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.MestoID, "MestoID", htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.DropDownList("MestoID", null, htmlAttributes: new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.MestoID, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Date, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.Date, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Date, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <div class="col-md-offset-2 col-md-10"> @Html. <input type="submit" value="Create" class="btn btn-default" /> </div> </div> </div> }
[HttpPost] [ValidateAntiForgeryToken] public ActionResult Create([Bind(Include = "ID,CustomerName,PoezdID,VaqonID,MestoID,Tarix")] Reqistration reqistration) { if (ModelState.IsValid ) { db.Reqistration.Add(reqistration); db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.PoezdID = new SelectList(db.Poezd, "ID", "Name", reqistration.PoezdID); ViewBag.MestoID = new SelectList(db.MestoVaqon, "ID", "ID", reqistration.MestoID); ViewBag.VaqonID = new SelectList(db.Vaqon, "ID", "Vaqon1", reqistration.VaqonID); return View(reqistration); }
это registrationsController