我的MVC应用程序我在jQuery对话框中打开局部视图当我提交表单并且我的服务器端验证失败时,在按钮单击事件上。
现在,我想在弹出窗口中显示来自服务器端的警报消息,例如,播放消息。现在请告诉我朋友如何在弹出窗口打开警报消息当我点击警报好的按钮我的警报应该关闭我的 在服务器端验证失败的情况下,不应关闭对话框并保留对话框中的数据。
单击按钮代码时的对话框打开代码如下:
$("body").on("click", "#modal2", function (e) {
var url = $(this).attr('href');
$("#dialog-edit").dialog({
title: 'Add Ticket',
autoOpen: true,
resizable: false,
width: '65%',
height: 400,
modal: true,
draggable: false,
open: function (event, ui) {
$(this).load(url);
$('.ui-widget-overlay').addClass('custom-overlay');
},
close: function (event, ui) {
$(this).dialog('close');
$('.ui-widget-overlay').removeClass('custom-overlay');
}
});
$("#dialog-edit").dialog('open');
return false;
});
对话框中显示的数据通过ID代码如下:
[HttpGet]
public ActionResult Ticket(int id)
{
try
{
if (ModelState.IsValid)
{
int suserid = Convert.ToInt32(Session["ID"]);
var Station = cn.usp_FlightsStatusGrid(suserid).Where(x => x.ID == id).ToList();
//ViewBag.Station = new SelectList(Station, "StationID", "Station");
ViewData["Employees"] = cn.usp_EditmodeFlightDetailInformation(id).FirstOrDefault();
ViewBag.fhid = id;
List<usp_ErrorRecordsList_Result> model = cn.usp_ErrorRecordsList(id).ToList();
int a = cn.usp_ErrorRecordsList(id).Where(x => x.POI == "").ToList().Count;
return PartialView("_AddTicket", model);
}
}
catch (Exception ex)
{
string sActionName = this.ControllerContext.RouteData.Values["action"].ToString();
string sControllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
cn.usp_ErrorLogDetails(sControllerName + "/" + sActionName, ex.Message);
Session["ErrorMsg"] = ex.Message;
return RedirectToAction("Error", "Error");
}
return View();
}
表格提交代码如下:
$("#btnSave").click(function () {
var retval = ISVALID();
//ISVALID();
if (retval == true)
{
$('#myForm2').submit();
}
else {
return false;
}
});
通过后期方法保存数据如下:
[HttpPost]
public ActionResult Ticket(List<UCR.Models.usp_ErrorRecordsList_Result> lstmissingrecord,int Id)
{
int ID = Convert.ToInt32(Session["IDmissingticket"]);
List<usp_ErrorRecordsList_Result> model = cn.usp_ErrorRecordsList(ID).Where(x => x.POI != null).ToList();
var updatedticket = lstmissingrecord.Where(x => x.TicketCurrency != null && x.POI != null && x.AdultInfant != null && x.TransitPax != null).ToList();
int suserid = Convert.ToInt32(Session["ID"]);
int count = 0;
string scurrencymsg = "Please provide correct information for Ticket No.";
foreach (var ticket in updatedticket)
{
if (!(cn.tblCountries.Any(x => x.CurrencyCode == ticket.TicketCurrency.ToUpper().Trim()) && cn.tblCities.Any(x => x.CityCode == ticket.POI.ToUpper().Trim())))
{
scurrencymsg += ticket.TicketNo + ",";
string SuccessTickeMsg = scurrencymsg.Substring(0, scurrencymsg.Length - 1);
TempData["TickeMsg"] = SuccessTickeMsg; // Validation Gets Failed.And I want to have a alert message Here and I click on alert ok button my alrert box should get closed but Dialog box should not get closed.And Data should get retained in Dialog Box.
return RedirectToAction("Uploadpassengers", "Home");
}
}
foreach (var ticket in updatedticket)
{
//if (cn.tblCountries.Any(x => x.CurrencyCode == ticket.TicketCurrency.ToUpper().Trim()) == true && cn.tblCities.Any(x => x.CityCode == ticket.POI.ToUpper().Trim()))
//{
cn.usp_InsertTicketmissingdetailInformationsbyuser(Convert.ToInt32(ticket.PaxID), ticket.TicketNo, ticket.PaxName, ticket.TicketCurrency.ToUpper().Trim(), ticket.AdultInfant.ToUpper().Trim(), ticket.TransitPax.ToUpper().Trim(), suserid, ticket.POI.ToUpper().Trim(), ticket.DateOfIssue);
cn.SaveChanges();
count = count + 1;
//}
// else
//{
// scurrencymsg += ticket.TicketNo + ",";
//}
}
if (lstmissingrecord.Count == count)
{
cn.usp_StatusUpdation(Id);
cn.SaveChanges();
}
if (scurrencymsg == "Please provide correct information for Ticket No.")
{
string SuccessTickeMsg = ConstantMsg.C1009;
TempData["TickeMsg"] = SuccessTickeMsg;
return RedirectToAction("Uploadpassengers", "Home");
}
return RedirectToAction("Uploadpassengers", "Home");
//else {
// string SuccessTickeMsg = scurrencymsg.Substring(0, scurrencymsg.Length - 1);
// var response = new Response(true, SuccessTickeMsg);
// return Json(response.v2);
//}
}