Begin Form:
@using (Html.BeginForm("Index","AddBooking",FormMethod.Post))
{
@Html.AntiForgeryToken()
<div class="col-md-8">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group col-md-6">
@Html.LabelFor(model => model.cityid, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.cityid, Model.CityList.Select(m => new SelectListItem { Text = m.Name, Value = Convert.ToString(m.ID) }), "SELECT City", new { @class = "select-select2", style = "width: 100%;" })
@*@Html.ValidationMessageFor(model => model.cityid,"", new { @class = "text-danger" })*@
</div>
</div>
<div class="form-group col-md-6">
@Html.LabelFor(model => model.mobile, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.mobile, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus" } })
@*@Html.EditorFor(model => model.mobile, new { htmlAttributes = new { autofocus = "autofocus" } })*@
<label id="cusstatus" class="text-danger"></label>
@Html.ValidationMessageFor(model => model.mobile, "", new { @class = "text-danger" })
</div>
</div>
<!-- Bootstrap Typeahead (class is initialized in js/app.js -> uiInit()), for extra usage examples you can check out https://github.com/bassjobsen/Bootstrap-3-Typeahead -->
<div class="form-group col-md-6">
@Html.LabelFor(model => model.name, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.name, new { htmlAttributes = new { @class = "form-control input-typeahead", @autocomplete = "off", @placeholder = "Search Customers.." } })
@Html.ValidationMessageFor(model => model.name, "", new { @class = "text-danger" })
</div>
</div>
@*<div class="form-group col-md-6">
@Html.LabelFor(model => model.CompanyID, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.CompanyID, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CompanyID, "", new { @class = "text-danger" })
</div>
</div>*@
@*<div class="form-group col-md-6">
@Html.LabelFor(model => model.CompanyName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.CompanyName, new { htmlAttributes = new { @class = "form-control" } })
<label id="comstatus" class="text-danger"></label>
</div>
</div>*@
@*<div class="form-group col-md-6" style="visibility:hidden">*@
<div class="form-group col-md-6">
@Html.LabelFor(model => model.email, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.email, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.email, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group col-md-6">
@Html.LabelFor(model => model.fromloc, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.fromloc, new { htmlAttributes = new { @class = "form-control" } })
<ul id="lst" style="list-style-type:none;background-color:white"></ul>
@Html.ValidationMessageFor(model => model.fromloc, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group col-md-6">
@Html.LabelFor(model => model.toloc, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.toloc, new { htmlAttributes = new { @class = "form-control" } })
<ul id="lst1" style="list-style-type:none;background-color:white"></ul>
@Html.ValidationMessageFor(model => model.toloc, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group col-md-6">
@Html.LabelFor(model => model.pickupdate, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.Editor("txtpickupdate", DateTime.Now.ToShortDateString(), new { htmlAttributes = new { @class = "form-control input-datepicker", @placeholder = "mm/dd/yyyy" } }) @*, @id="MyDate" } })*@
@*@Html.EditorFor(model => model.pickupdate, new { htmlAttributes = new { @class = "form-control input-datepicker", @placeholder = "dd/mm/yy" } })*@
@Html.ValidationMessageFor(model => model.pickupdate, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group col-md-6">
@Html.LabelFor(model => model.pickuptime, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<div class="input-group bootstrap-timepicker">
@Html.Editor("txtpickuptime", (string)ViewBag.pickuptime, new { htmlAttributes = new { @class = "form-control input-timepicker" } })
@*@Html.EditorFor(model => model.pickuptime,(string)ViewBag.pickuptime, new { htmlAttributes = new { @class = "form-control input-timepicker" } })*@
<span class="input-group-btn">
<a href="javascript:void(0)" class="btn btn-effect-ripple btn-primary"><i class="fa fa-clock-o"></i></a>
</span>
</div>
@Html.ValidationMessageFor(model => model.pickuptime, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group col-md-6">
@Html.LabelFor(model => model._packagetype, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model._packagetype, Model.PackageTypeList.Select(m => new SelectListItem { Text = m.Package, Value = Convert.ToString(m.Package_id) }), "Select", new { @class = "select-select2", style = "width: 100%;" })
@*@Html.ValidationMessageFor(model => model.packagetype, "", new { @class = "text-danger" })*@
</div>
</div>
<div class="form-group col-md-6">
@Html.LabelFor(model => model.packageweight, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.packageweight, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.packageweight, "", new { @class = "text-danger" })
</div>
</div>
<div id="divbooktype" class="form-group col-md-6">
@Html.LabelFor(model => model.BookType, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.BookType, Model.BookTypeList.Select(m => new SelectListItem { Text = m.name, Value = Convert.ToString(m.id) }), "Select", new { @class = "select-select2", style = "width: 100%;" })
@*@Html.ValidationMessageFor(model => model.packagetype, "", new { @class = "text-danger" })*@
</div>
</div>
<div id="divvehicletype" class="form-group col-md-6" style="display:none;">
@Html.LabelFor(model => model.VehicleType, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.VehicleType, Model.VehicleList.Select(m => new SelectListItem { Text = m._vehicle, Value = Convert.ToString(m._id) }), "Select", new { @class = "select-select2", style = "width: 100%;" })
@*@Html.ValidationMessageFor(model => model.packagetype, "", new { @class = "text-danger" })*@
</div>
</div>
<div id="divpackagetype" class="form-group col-md-6" style="display:none;">
@Html.LabelFor(model => model.PackageType, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.PackageType, Model.PackageList.Select(m => new SelectListItem { Text = m._hours, Value = Convert.ToString(m._id) }), "Select", new { @class = "select-select2", style = "width: 100%;" })
@*@Html.ValidationMessageFor(model => model.packagetype, "", new { @class = "text-danger" })*@
</div>
</div>
<div id="divintercitytype" class="form-group col-md-6" style="display:none;">
@Html.LabelFor(model => model.InterCityType, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.InterCityType, Model.InterCityList.Select(m => new SelectListItem { Text = m._intercity, Value = Convert.ToString(m._id) }), "Select", new { @class = "select-select2", style = "width: 100%;" })
@*@Html.ValidationMessageFor(model => model.packagetype, "", new { @class = "text-danger" })*@
</div>
</div>
<div class="form-group col-md-6">
@Html.LabelFor(model => model.distance, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.distance, new { htmlAttributes = new { @class = "form-control", @readonly = "readonly" } })
@Html.ValidationMessageFor(model => model.distance, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group col-md-6">
@Html.LabelFor(model => model.CompanyID, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.CompanyID, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CompanyID, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group col-md-6">
@Html.LabelFor(model => model.CompanyName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.CompanyName, new { htmlAttributes = new { @class = "form-control" } })
<label id="comstatus" class="text-danger"></label>
</div>
</div>
<div class="form-group col-md-6">
@Html.LabelFor(model => model.Remarks, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Remarks, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Remarks, "", new { @class = "text-danger" })
</div>
</div>
@* <div class="form-group col-md-6">
@Html.LabelFor(model => model.email, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.email, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.email, "", new { @class = "text-danger" })
</div>
</div>*@
<div class="form-group col-md-6">
<div class="col-md-offset-2 col-md-2">
<input type="submit" name="book" value="Book Now" class="btn btn-effect-ripple btn-primary" />
</div>
<div class="col-md-offset-2 col-md-2">
<input type="submit" name="enquiry" value="Enquiry" class="btn btn-effect-ripple btn-danger" />
</div>
<div class="col-md-offset-2 col-md-2">
<input type="submit" name="cancel" value="Cancel" class="btn btn-effect-ripple btn-success" />
</div>
</div>
</div>
<div class="col-md-4">
<!-- Mixed Chart Block -->
<div class="block full">
<!-- Mixed Chart Title -->
<div class="block-title">
<h2>Fare Estimation</h2>
</div>
<!-- END Mixed Chart Title -->
<div id="chart-mixed" style="height: 380px; padding: 0px; position: relative; font-size:19px;">
<div class="col-md-6 text-danger">
@*Base Minutes*@
Base Min.
</div>
<div class="col-md-6">
<label id="baseminutes" class="text-danger">0.0</label>
</div>
<div class="col-md-6 text-danger">
@*Base Distance*@
Base Dist.
</div>
<div class="col-md-6">
<label id="basedistance" class="text-danger">0.0</label>
</div>
<div class="col-md-6 text-danger">
@*Base Fare*@
Base Fare
</div>
<div class="col-md-6">
<label id="baseFare" class="text-danger">0.0</label>
</div>
<div class="col-md-6 text-danger">
@*Additional KM Fare*@
Add. KM Fare
</div>
<div class="col-md-6">
<label id="additionalKM" class="text-danger">0.0</label>
</div>
<div class="col-md-6 text-danger">
@*Additional Minute*@
Add. Minute
</div>
<div class="col-md-6">
<label id="additionalMinute" class="text-danger">0.0</label>
</div>
<div class="col-md-6 text-danger">
@*Approximate Fare*@
Approx. Fare
</div>
<div class="col-md-6">
<label id="appFare" class="text-danger">0.0</label>
</div>
</div>
</div>
<!-- END Mixed Chart Block -->
</div>
}
Index Method in Controller:
[HttpPost]
public ActionResult Index(AddBooking adbook, string book, string enquiry, string cancel)
{
var cityid = Session["CityID"] as string;
if (!string.IsNullOrEmpty(book))
{
DataAccess da = new DataAccess();
var _cityid = Request.Form["cityid"].ToString();
var _packagetype = Request.Form["_packagetype"].ToString();
var _booktype = Request.Form["BookType"].ToString();
var _vehicleid = Request.Form["VehicleType"].ToString();
var _packageid = Request.Form["PackageType"].ToString();
var _intecity = Request.Form["InterCityType"].ToString();
string _pckdate = Convert.ToDateTime(Request.Form["txtpickupdate"]).ToShortDateString() + " " + Convert.ToDateTime(Request.Form["txtpickuptime"]).ToShortTimeString();
adbook.pickupdate = DateTime.ParseExact(_pckdate, "MM/dd/yyyy HH:mm tt", System.Globalization.CultureInfo.InvariantCulture);
adbook.status = 1;
if (da.InsertBooking(adbook, _cityid, _packagetype, _booktype, _vehicleid, _packageid, _intecity) == true)
ViewBag.Message = "Customer Booked successfully!";
else
ViewBag.Message = "Booking Not Success";
}
else if (!string.IsNullOrEmpty(enquiry))
{
DataAccess da = new DataAccess();
var _cityid = Request.Form["cityid"].ToString();
var _packagetype = Request.Form["_packagetype"].ToString();
var _booktype = Request.Form["BookType"].ToString();
var _vehicleid = Request.Form["VehicleType"].ToString();
var _packageid = Request.Form["PackageType"].ToString();
var _intecity = Request.Form["InterCityType"].ToString();
string _pckdate = Convert.ToDateTime(Request.Form["txtpickupdate"]).ToShortDateString() + " " + Convert.ToDateTime(Request.Form["txtpickuptime"]).ToShortTimeString();
adbook.pickupdate = DateTime.ParseExact(_pckdate, "MM/dd/yyyy HH:mm tt", System.Globalization.CultureInfo.InvariantCulture);
adbook.status = 6;
if (da.InsertBooking(adbook, _cityid, _packagetype, _booktype, _vehicleid, _packageid, _intecity) == true)
ViewBag.Message = "Enquiry Added successfully!";
else
ViewBag.Message = "Enquiry Not Success";
}
else if (!string.IsNullOrEmpty(cancel))
{
DataAccess da = new DataAccess();
var _cityid = Request.Form["cityid"].ToString();
var _packagetype = Request.Form["_packagetype"].ToString();
var _booktype = Request.Form["BookType"].ToString();
var _vehicleid = Request.Form["VehicleType"].ToString();
var _packageid = Request.Form["PackageType"].ToString();
var _intecity = Request.Form["InterCityType"].ToString();
string _pckdate = Convert.ToDateTime(Request.Form["txtpickupdate"]).ToShortDateString() + " " + Convert.ToDateTime(Request.Form["txtpickuptime"]).ToShortTimeString();
adbook.pickupdate = DateTime.ParseExact(_pckdate, "MM/dd/yyyy HH:mm tt", System.Globalization.CultureInfo.InvariantCulture);
adbook.status = 5;
if (da.InsertBooking(adbook, _cityid, _packagetype, _booktype, _vehicleid, _packageid, _intecity) == true)
ViewBag.Message = "Cancelled successfully!";
else
ViewBag.Message = "Cancelled Not Success";
}
DataAccess _da = new DataAccess();
AddBooking adb = new AddBooking();
adb.CityList = _da._returnCityList();
adb.PackageTypeList = _da._returnPackageTypeList();
adb.BookTypeList = _da._returnBookingTypeList(cityid);
adb.VehicleList = _da._returnVehicleList(cityid);
adb.PackageList = _da._returnPackageList(cityid);
adb.InterCityList = _da._returnInterCityList(cityid);
ModelState.Clear();
ViewBag.pickupdate = DateTime.Now.ToShortDateString();
ViewBag.pickuptime = DateTime.Now.ToShortTimeString();
return View(adb);
}
When Button Book is trigger in the view page its shows the error--
An item with the same key has already been added