पर अपवाद संदेश मैं इस बॉक्स में एक jQuery संवाद खोलता हूं, मैं एक सेव/रद्द करता हूं। सहेजने के लिए, मैं अपने नियंत्रक को कॉल करता हूं, कुछ सत्यापन करता हूं, अपवाद (MyPersonalException) को सहेजता या फेंक देता हूं। यदि अपवाद है, तो मैं पॉपअप में प्रदर्शित करने के लिए एक और दृश्य ("MessageError" दृश्य) वापस कर देता हूं। मैं सिर्फ मोडल बॉक्स में संदेश "MyPersonalException"यूआई
मेरे सवालों में उपलब्ध देखना चाहते हैं: 1. काम है कि लेकिन केवल Firefox के साथ नहीं आईई Chrome 2. नहीं वहाँ एक अन्य रास्ता नहीं है कि की एक lof देखो है, क्योंकि सिर्फ एक संदेश diplay करने के लिए कोड।
इस तरह नियंत्रक देखो:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult SaveOrUpdate(Guid id, string firstName, string LastName)
{
try
{
Employee employee = new Employee() { Id = id, FirstName = firstName, LastName = LastName };
_employeeService.SaveOrUpdate(employee);
return Index();
}
catch (MyPersonalException ex)
{
_model.ErrorMessage = ex.Message;
return View("MessageError", _model);
}
catch (Exception ex)
{
_model.ErrorMessage = ex.Message;
return View("MessageError", _model);
}
}
संवाद बॉक्स कॉल करने के लिए, मैं इस कोड
jQuery (document) .ready (function() { $ (function() { का उपयोग/* var name = $ ("# firstName"), ईमेल = $ ("# अंतिम नाम"), पासवर्ड = $ ("# isactive"), allFields = $ ([])। जोड़ें (नाम) .add (ईमेल) .add (पासवर्ड), टिप्स = $ ("# मान्य टिप्स"); */
$("#dialog").dialog({
bgiframe: true,
autoOpen: false,
modal: true,
buttons: {
Save: function() {
$.ajax({
type: "POST",
url: "/Employee/SaveOrUpdate",
data: {
id: getId(),
firstName: getFirstName(),
lastName: getLastName()
},
success: function(data) {
if (jqueryShowResult(data))
$("#DisplayError").html(data);
else {
employeeId = 0;
$(this).dialog('close');
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
}
})
},
Cancel: function() {
employeeId = 0;
$(this).dialog('close');
}
},
close: function() {
$("#gridEmpoyee").trigger("reloadGrid");
},
open: function() {
$.ajax({
type: "POST",
url: "/Employee/GetEmployee",
data: {
id: employeeId
},
success: function(data) {
$("#employeeDetail").html(data);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
}
})
}
});
});
});
jQueryShowResult
<script type="text/javascript">
jqueryShowResult = function(msg) {
var browser;
try //Internet Explorer
{
xmlDocTest = new ActiveXObject("Microsoft.XMLDOM");
browser = "IE";
}
catch (e) {
browser = "FF";
}
if (browser == "IE") {
try {
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = "false";
xmlDoc.loadXML(msg);
var message = xmlDoc.getElementsByTagName("message")[0].childNodes[0].nodeValue;
var code = xmlDoc.getElementsByTagName("code")[0].childNodes[0].nodeValue;
return false;
}
catch (e) {
return true;
}
}
else {
var code = $(msg).find('code').text();
var message = $(msg).find('message').text();
if (code == "500") {
return false;
}
else {
return true;
}
}
};
</script>
मैंने नीचे दिए गए उत्तर को अपडेट किया है, यह आपको jQuery AJAX ऑब्जेक्ट को अनुकूलित किए बिना जो भी करना चाहते हैं उसे करने की अनुमति दे सकता है। –