Click here to Skip to main content
14,924,198 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.
Member 13058758 13-May-20 8:05am
   
yup you need a partial view html code


@model IEnumerable<fzpc.dal.main>





@model IEnumerable<FZPC.DAL.Main>




<table class="table table-bordered text-center">
    <tr style=" background-color:#333333; color:white; text-align:center">
        <th></th>
        <th>
            رقم الشهادة الجمركية
        </th>

        <th>
            رقم اللوحة
        </th>

        <th>
            رقم الشاسيه
        </th>

        <th>
            سنة الصنع
        </th>

        <th>
            موديل السيارة
        </th>

        <th>
            ماركة السيارة
        </th>

        <th>
            الأسم
        </th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @*@Html.ActionLink("Edit", "Edit", new { id = item.id }) |*@
                @Html.ActionLink(" ", "Details", null, new { id = item.id, }, new { @class = "fas fa-search-plus mr-2" })
                @*|
                    @Html.ActionLink("Delete", "Delete", new { id = item.id })*@
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.CustomsCertNum)
            </td>

            <td>
                @Html.DisplayFor(modelItem => item.NumPlate)
            </td>

            <td>
                @Html.DisplayFor(modelItem => item.ChassisNO)
            </td>

            <td>
                @Html.DisplayFor(modelItem => item.ModelYear)
            </td>

            <td>
                @Html.DisplayFor(modelItem => item.CarModel)
            </td>

            <td>
                @Html.DisplayFor(modelItem => item.CarBrand)
            </td>

            <td>
                @Html.DisplayFor(modelItem => item.Name)
            </td>
        </tr>
    }

</table>
Richard Deeming 13-May-20 12:33pm
   
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.)
Member 13058758 14-May-20 4:17am
   
Thanks It done please make it as solution

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[^]
   

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