【发布时间】:2016-02-17 14:05:42
【问题描述】:
我目前正在发出从我的视图“Index.cshtml”发送的数据库查询请求,但是如果用户输入的选择没有返回任何结果,我会尝试向用户发送消息。目前,我找到了一个示例,该示例为用户提供了一个 JS 框,当他们的查询返回为空时向他们显示一条消息。但是,当他们收到消息时,会将他们重定向到空白页面。
我的目标是 当他们的查询请求返回为空时,让用户收到一条消息。并且只需重新加载网页,以便他们重试查询。这是我拥有的以下代码。
代码
public ActionResult GetClientList(int? marketGroup, int? engagementOffice, int? engagementpartner, int? engagementStatus)
{
List<Engagement> QueryResult = PMService.GetRequestedEngagments(marketGroup, engagementOffice, engagementpartner, engagementStatus);
if(QueryResult.Count==0)
{
return View("<script language='javascript' type='text/javascript'>alert('Your Search Came Back Empty Please Retry ');</script>");
}
var writetofile = PMService.BuildCsvString(QueryResult);
var bytefile = Encoding.UTF8.GetBytes(writetofile);
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=SqlExport.csv");
Response.Charset = "";
Response.ContentType = "application/text";
Response.BinaryWrite(bytefile);
Response.Flush();
Response.End();
return View();
}
目前我的情况是如果列表返回空并给出消息,但之后会将它们带到空白页面。
【问题讨论】:
标签: javascript c# model-view-controller