I am new in asp.net mvc.Pleace help me to check if exist the value which I wrote in my database.4columns value should check and return message
What I have tried:
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; }
}
}
my reqistration class(check if VaqonID && PoezdID && MestoID && Date)have exist.
@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);
}
this is registrationsController