[英]How to show the Error message when there is nodata?
I'm Working with Asp .net MVC3,Following is my controller method, 我正在使用Asp .net MVC3,以下是我的控制器方法,
public ActionResult TravelReadyAdminDownloadInvoke(int intId, int intMonth)
{
TravelReadyAdminModel objTravelReadyAdminModel = new TravelReadyAdminModel();
try
{
if (intId == 3)
{
objTravelReadyAdminModel = objTravelReadyAdminModel.GetTravelReadyAdminRawExport(intId, intMonth);
if (objTravelReadyAdminModel.lstRawDataEntities == null)
{
}
else
{
objTravelReadyAdminModel.ExportTravelReadyAdmin("TRAdminRawData", objTravelReadyAdminModel.lstRawDataEntities);
}
}
}
catch (Exception ex)
{
ILogManager LogManager = new LogManager();
var frame = new StackFrame(0);
LogManager.CallLogging(frame, ex.Message, ex.StackTrace);
return RedirectToAction("Error", "Common");
}
return View();
}
what code i need to give inside if condition to show the error message box? 如果要显示错误消息框,我需要在里面输入什么代码?
Create an _MessageBox
partial like this (I'm using bootstrap alert here): 创建这样的_MessageBox
部分(我在这里使用引导警报):
if (TempData.ContainsKey("warning"))
{
<div class="alert alert-danger">
<button type="button" class="close" data-dismiss="alert">x</button>
@TempData["warning"]
</div>
}
In your layout folder add this somewhere: 在布局文件夹中,将此添加到某处:
@Html.Partial("_MessageBox")
In your controller add this (I prefer to call it in base controller that I can re-use): 在您的控制器中添加此代码(我更喜欢在可以重复使用的基本控制器中调用它):
protected void Alert(string message)
{
// Check to see if it exists already and removes it
if (TempData.ContainsKey("warning"))
TempData.Remove("warning");
TempData.Add("warning", message);
}
Then call it like this in your controller: 然后在您的控制器中这样调用它:
catch (Exception ex)
{
ILogManager LogManager = new LogManager();
var frame = new StackFrame(0);
LogManager.CallLogging(frame, ex.Message, ex.StackTrace);
Alert("Warning message");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.