Click here to Skip to main content
15,886,807 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my Razor View:
 @using (Ajax.BeginForm("Search", "Mains", new AjaxOptions() {OnSuccess="on" ,UpdateTargetId = "Lists", HttpMethod = "Post", InsertionMode = InsertionMode.Replace }))
            {
                <div class="form-control d-inline ">
                    <button id="seabox"><span class="fas fa-search" style="color:#bbb6b6"></span></button>
                    @Html.TextBox("search", null, new { @id = "seabox", @placeholder = "Search" })
                </div>
            }

<div id="Lists">  
</div>


@section scripts{
        @Scripts.Render("~/bundles/jqueryunobtrusive")
        @Scripts.Render("~/Scripts/jquery.unobtrusive-ajax.min.js")       
    }
And this is my controller action:
public ActionResult Search(string search)
        {
            var names = db.Mains.Where
                (p => p.Name.Contains(search)
            || p.IDNumber.Contains(search)
            //|| p.Payment.StartsWith(search)
            || p.ChassisNO.Contains(search)
            || p.PlaceOfWork.Contains(search)
            || p.PlaceOfBirth.Contains(search)
            || p.NumPlate.Contains(search)
            || p.CarBrand.Contains(search)
            || p.CustomsCertNum.Contains(search)
            || p.CarModel.Contains(search)
            || p.ModelYear.StartsWith(search)
            || p.Status.StartsWith(search)
            || p.Cases.StartsWith(search)
            || p.PaymentDate.ToString().Contains(search)            
            );            

            return PartialView("_search", names.ToList());
            
        }
after click search partial view open in new tab i want to show it in the same page

What I have tried:

i tried to change jquery links
Posted
Updated 14-May-20 0:13am
v2
Comments
ZurdoDev 13-May-20 7:24am    
Is "search" a button or a textbox?
Member 13058758 13-May-20 7:29am    
I write parameter in textbox named search and click button to submit do all action in controller and retrieve a list but in another page not in the same
ZurdoDev 13-May-20 7:50am    
But where is the code for the search button?
Member 13058758 13-May-20 7:54am    
i don't understand what do you mean? you mean controller c# code ?

I put it in my question

public ActionResult Search(string search)
ZurdoDev 13-May-20 7:58am    
Nope. Somewhere there is html that is rendering your search button and code for what to do when clicked. If it is opening in a new window, that is a client side issue.

1 solution

As discussed in the comments, you need to check your browser's developer console for errors. It's possible that the AJAX form is failing, and falling back to submitting normally.

(You might need to enable the "persist logs" option, so that the console output isn't lost when a new page loads.)

Firefox: Opening the Web Console - Firefox Developer Tools | MDN[^]
Chrome: Console Overview  |  Tools for Web Developers  |  Google Developers[^]
Edge: DevTools - Console - Microsoft Edge Development | Microsoft Docs[^]
 
Share this answer
 

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