jQuery 대화 상자를 엽니 다.이 상자에는 저장/취소가 있습니다. 저장하려면 컨트롤러를 호출하거나 유효성을 검사하거나 Exception (MyPersonalException)을 저장하거나 throw합니다. 예외가 있으면 팝업에 표시 할 다른보기 ("MessageError"보기)를 반환합니다. 그의 LOF 모양입니다 때문에 다른 방법이 있나요 하지만 파이어 폭스와 작업입니다 1.하지 IE는하지 2. 크롬 : 난 그냥 모달 상자에서 "MyPersonalException"UI에 대한 예외 메시지
내 질문에서 사용할 수있는 메시지를보고 싶어 코드를 표시하기 만하면됩니다. 이 같은
컨트롤러의 모양을
[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를 (문서) .ready (함수() { $ (함수() { 를 사용/* var name = $ ("# firstName"), email = $ ("# lastName"), password = $ ("# isActive"), allFields = $ ([]). add (이메일) .add (비밀번호), 팁 = $ ("# validateTips"); */
$("#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 객체를 사용자 정의하지 않고도 원하는대로 할 수 있습니다. –