Click here to Skip to main content
15,887,446 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I make a page when I search in database if data not found it retrieve a message and redirect to another view
but when page load, it show empty page with text 2020

Certificate Razor view
<div class="row" style="margin-left:30%; margin-top:15px; width:85%;">
                @using (Ajax.BeginForm("SearchCerticate", "Mains", new AjaxOptions() { OnSuccess = "on", UpdateTargetId = "Lists", HttpMethod = "Post", InsertionMode = InsertionMode.Replace }))
                {
                    <div class="form-inline" style="flex-flow:unset" id="main">
                        @Html.ValidationSummary("", new { @style = "width:80%; color: red; margin-top:20px", @class = "validate" })
                        <button id="seabox" class="btn btn-secondary" style="width:40%; margin:15px;margin-top: 30px;">بحث</button>
                        @Html.TextBox("search", null, new { @id = "seabox", @placeholder = "بحث عن", @class = "form-control valid", @data_val = "true", @data_val_required = "ادخل البيانات", @style = "width:40%;" })
                    </div>
                }

            </div>

            <div id="Lists" class="row" style="margin: 0 auto; width:100%!important;">
            </div>


controller
public ActionResult Certificate(){              
           
            return View();
        }

        
        public ActionResult SearchCerticate(string search)
        {
            var searchcert = db.Mains.Where(
               p => p.Name.Contains(search)
            || p.IDNumber.Contains(search)
            || p.ChassisNO.Contains(search)
            || p.NumPlate.Contains(search)
            || p.CustomsCertNum.Contains(search));

            var cert = db.Mains.Where(
               p => p.Name.Contains(search)
            || p.IDNumber.Contains(search)
            || p.ChassisNO.Contains(search)
            || p.NumPlate.Contains(search)
            || p.CustomsCertNum.Contains(search)
            ).Select(p => p.id).FirstOrDefault();

            var searchcerts = searchcert.Count();
            if (searchcerts > 1)
            {
                TempData["Message"] = " too many data";
                return PartialView("_certificateResult", searchcert.ToList());
            }
            else if (searchcerts < 1)
            {
                TempData["Message"] = "no allow";
                return RedirectToAction("Certificate");
}


i need from controller redirect to page to search again

What I have tried:

I tried

replace 
return RedirectToAction("Certificate");

with return view ("Certificate");

and 
return RedirectToAction("Mains","Certificate");
and the same result empty page with 2020 text
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900