C# 当模型不返回任何数据时,如何在MVC4中显示视图中的消息?

C# 当模型不返回任何数据时,如何在MVC4中显示视图中的消息?,c#,asp.net-mvc-4,C#,Asp.net Mvc 4,嗨,我正在开发应用程序,我有5个文本框和搜索按钮。当我在文本框中输入数据并单击搜索时,对应的数据库匹配数据将显示在下表中。我已经实现了分页,它工作得很好。下面是代码 [HttpGet] public ActionResult Index(int? clientId, string dateofAction, int? doc_typeid, string employeeID,string citizenId,int? currentFilter, string filterd

嗨,我正在开发应用程序,我有5个文本框和搜索按钮。当我在文本框中输入数据并单击搜索时,对应的数据库匹配数据将显示在下表中。我已经实现了分页,它工作得很好。下面是代码

 [HttpGet]
        public ActionResult Index(int? clientId, string dateofAction, int? doc_typeid, string employeeID,string citizenId,int? currentFilter, string filterdateTime,int? filterdocType,string filteredemployeeID,string filteredcitizenId,int? page)
        {
            ViewBag.curpageNumber = page;

            logDetailsEnumeration model = new logDetailsEnumeration();
            DB_KYC3Entities db = new DB_KYC3Entities();
            var docTypes = from c in db.tm_doc_type select c;
            if (clientId != null)
            {
                page = 1;
            }
            else
            {
                clientId = currentFilter;
            }
            if(dateofAction!=null)
            {
                page = 1;
            }
            else
            {
                dateofAction = filterdateTime;
            }
            if(doc_typeid != null)
            {
                page = 1;
            }
            else
            {
                doc_typeid = filterdocType;

            }
            if(employeeID!=null)
            {
                page = 1;
            }
            else
            {
                employeeID = filteredemployeeID;
            }
            if(citizenId!=null)
            {
                page = 1;
            }
            else
            {
                citizenId = filteredcitizenId;
            }

            ViewBag.CurrentFilter = clientId;
            ViewBag.filterdateTime = dateofAction;
            int pageSize = 8;
            int pageNumber = (page ?? 1);
            VerificationLogBAL obj = new VerificationLogBAL();
            int docType = obj.GetDocDetails(doc_typeid?? default(int));
            List<logDetails> logDetails = obj.getlogDetails(clientId?? default(int), dateofAction, docType, employeeID, citizenId);
            IPagedList<logDetails> pagedLog = logDetails.ToPagedList(pageNumber, pageSize);
            model = new logDetailsEnumeration()
            {
                pageNum= pageNumber,
                doc_typeid = doc_typeid,
                Count=logDetails.Count,
                employeeID = employeeID,
                citizenId= citizenId,
                logDetails = pagedLog,
                doctype_name=new SelectList(docTypes, "doc_typeid", "doctype_name")
            };
            return View("Index",model);
            }
        }
[HttpGet]
公共操作结果索引(int?clientId、string dateofAction、int?doc_typeid、string employeeID、string citizenId、int?currentFilter、string filterdateTime、int?filterdocType、string filteredemployeeID、string filteredcitizenId、int?page)
{
ViewBag.curpageNumber=第页;
logDetailsEnumeration模型=新的logDetailsEnumeration();
DB_KYC3Entities DB=新的DB_KYC3Entities();
var docTypes=从db.tm_doc_type中的c选择c;
if(clientId!=null)
{
page=1;
}
其他的
{
clientId=当前过滤器;
}
如果(dateofAction!=null)
{
page=1;
}
其他的
{
dateofAction=filterdateTime;
}
if(doc_typeid!=null)
{
page=1;
}
其他的
{
doc_typeid=filterdocType;
}
if(employeeID!=null)
{
page=1;
}
其他的
{
employeeID=filteredemployeeID;
}
if(citizenId!=null)
{
page=1;
}
其他的
{
citizenId=filteredcitizenId;
}
ViewBag.CurrentFilter=clientId;
ViewBag.filterdateTime=操作日期;
int pageSize=8;
整数页码=(第1页);
VerificationLogBAL obj=新的VerificationLogBAL();
int docType=obj.GetDocDetails(doc_typeid??默认值(int));
List logDetails=obj.getlogDetails(clientId??默认值(int)、开始日期、docType、employeeID、citizenId);
IPagedList pagedLog=logDetails.ToPagedList(页码、页面大小);
模型=新的日志详细信息()
{
pageNum=页码,
doc\u typeid=doc\u typeid,
Count=logDetails.Count,
employeeID=employeeID,
citizenId=公民ID,
logDetails=pagedLog,
doctype\u name=新选择列表(doctype,“doc\u typeid”,“doctype\u name”)
};
返回视图(“索引”,模型);
}
}
这是我的视图代码

@using (Html.BeginForm("Index", "VerificationLog", FormMethod.Get))
    {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary(true)
        <div class="message"></div>

        <div class="loginUsernamePassword">
            <i class="fa fa-user"></i>
            <table width="100%" border="0" cellspacing="0" cellpadding="0" class="dataTable tableHover">
                <tr>
                    <th width="8%" scope="col">Client ID</th>
                    <th width="20%" scope="col">
                        <div class="form-box form-box-default">
                            @Html.TextBoxFor(x=>x.clientId, ViewBag.CurrentFilter as string, new { @id = "clientId", @placeholder = "Client ID", @class = "form-control", @maxlength = 20 })

                        </div>
                    </th>
                   <th width="10%" scope="col">Date Of Action</th>
                    <th width="20%" scope="col">
                        <div class="form-box form-box-default">
                         @Html.TextBoxFor(x=>x.dateofAction, ViewBag.filterdateTime as string,  new { @id = "dateofAction", @placeholder = "Date Of Action", @class = "txtBox form-control calender validate[required]" })
                            @*@Html.TextBox("dateofAction", ViewBag.filterdateTime as string,  new { @id = "dateofAction", @placeholder = "Date Of Action", @class = "txtBox form-control calender validate[required]" })*@


                        </div>
                    </th>
                    <th width="15%" scope="col">Type Of Document</th>
                    <th width="17%" scope="col">
                        <div class="form-box form-box-default">
                            @*@Html.TextBox("typeofDocument", ViewBag.filterdateTime as string, new { @id = "typeofDocument", @placeholder = "Type Of Document", @class = "form-control", @maxlength = 20 })*@
                            @Html.DropDownListFor(x=>x.doc_typeid,Model.doctype_name,"Select",new { @class = "form-control" })

                                                </div>
                    </th>
                </tr>
                <tr>
                    <th width="15%" scope="col">Employee ID</th>
                    <th width="17%" scope="col">
                        <div class="form-box form-box-default">
                            @Html.TextBoxFor(x=>x.employeeID, Model.employeeID, new { @id = "employeeID", @placeholder = "Employee ID", @class = "form-control", @maxlength = 20 })

                        </div>
                    </th>
                    <th width="15%" scope="col">Citizen ID</th>
                    <th width="17%" scope="col">
                        <div class="form-box form-box-default">
                            @Html.TextBoxFor(x=>x.citizenId, Model.citizenId, new { @id = "citizenId", @placeholder = "Citizen ID", @class = "form-control", @maxlength = 20 })

                        </div>
                    </th>
                    <th width="10%" scope="col" colspan="2">
                        <input type="submit" value="Search" class="btn btn-primary btn-cons search" />
                </tr>
            </table>

            </div>
            }

        </div>

        @if (Model != null && Model.logDetails.Count != 0)
        {
            <br />
            <h2>Verification Log</h2>
            <br />
            <div id="GridDetails">
                <table width="100%" border="0" cellspacing="0" cellpadding="0" class="dataTable tableHover">
                    <tr>
                        @*<th>@Html.ActionLink("Label", "Index", new { sortOrder = ViewBag.LabelSortParm, currentFilter = ViewBag.CurrentFilter, filterdateTime = ViewBag.filterdateTime, filterdocType = Model.doc_typeid, filteredemployeeID = Model.employeeID, filteredcitizenId = Model.citizenId, Page = ViewBag.curpageNumber })</th>*@
                        <th>Label</th>
                        <th>Value</th>
                        <th>UpdatedOn</th>
                        <th>UpdatedBy</th>
                        <th>UpdatedStatus</th>
                        <th>RejectComment</th>
                    </tr>
                    @foreach (var group in Model.logDetails)
                    {
                        <tr>
                            <td>@group.contentLabel</td>
                            <td>@group.contentValue</td>
                            <td>@group.updatedOn</td>
                            <td>@group.updatedBy</td>
                            <td>@group.updatedStatus</td>
                            <td>@group.rejectComment</td>
                        </tr>

                    }
                </table>

                @Html.PagedListPager(Model.logDetails, page => Url.Action("Index",
new { page, currentFilter = ViewBag.CurrentFilter, filterdateTime=ViewBag.filterdateTime, filterdocType= Model.doc_typeid, filteredemployeeID = Model.employeeID, filteredcitizenId = Model.citizenId }))
                Page @(Model.logDetails.PageCount < Model.logDetails.PageNumber ? 0 : Model.logDetails.PageNumber) of @Model.logDetails.PageCount
            </div>
@使用(Html.BeginForm(“Index”、“VerificationLog”、FormMethod.Get))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
客户端ID
@Html.TextBoxFor(x=>x.clientId,ViewBag.CurrentFilter作为字符串,新的{@id=“clientId”,@placeholder=“Client id”,@class=“form control”,@maxlength=20})
行动日期
@Html.TextBoxFor(x=>x.dateofAction,ViewBag.filterdateTime作为字符串,新的{@id=“dateofAction”,@placeholder=“操作日期”,@class=“txtBox表单控件日历验证[必需]”)
@*@TextBox(“dateofAction”,ViewBag.filterdateTime作为字符串,新的{@id=“dateofAction”,“占位符=“操作日期”,“@class=“txtBox表单控件日历验证[必需]”)*@
文件类型
@*@TextBox(“typeofDocument”,ViewBag.filterdateTime作为字符串,新的{@id=“typeofDocument”,@placeholder=“Document类型”,@class=“form control”,@maxlength=20})*@
@Html.DropDownListFor(x=>x.doc\u typeid,Model.doctype\u name,“Select”,new{@class=“form control”})
员工ID
@Html.TextBoxFor(x=>x.employeeID,Model.employeeID,新的{@id=“employeeID”,@placeholder=“employeeID”,@class=“form control”,@maxlength=20})
公民身份证
@Html.TextBoxFor(x=>x.citizenId,Model.citizenId,new{@id=“citizenId”、@placeholder=“citizenId”、@class=“form control”、@maxlength=20})
}
@if(Model!=null&&Model.logDetails.Count!=0)
{

验证日志
@*@ActionLink(“Label”,“Index”,new{sortOrder=ViewBag.LabelSortParm,currentFilter=ViewBag.currentFilter,filterdateTime=ViewBag.filterdateTime,filterdocType=Model.doc_typeid,filterdemployeeid=Model.employeeID,filterdcitizenid=Model.citizenId,Page=ViewBag.curpageNumber})*@ 标签 价值 更新 更新人 更新状态 拒绝评论 @foreach(Model.logDetails中的var组) { @group.contentLabel @c组