1

I've this scenario:

Site.Master


    ...               
    <%= Html.TextBox("ricerca") %>
    <img src="" alt ="" id="search" />
    ...

   <script type="text/javascript">
        $(function() {
            $('#search').click(function() {
                var valueSearch = $('#ricerca').val();
                Search(valueSearch);
            });
        });
        function Search(valueSearch) {
            $.ajax({
                type: "POST",
                url: "/Home/Search",
                data: "value=" + valueSearch
            });
        }

HomeController


    [HttpPost]
    public ActionResult Search(string value)
    {
        //...logic search
        return View();
    }

When i click on image called correctly the Search action, but after "Return View();" don't load the Search view (positioned in the folder Home)

Why don't show?

1 Answer 1

1

At no point are you inserting the data returned from the server into the document. That needs to happen within $.ajax's success callback:

$.ajax({
    type: "POST",
    url: "/Home/Search",
    data: "value=" + valueSearch,
    success: function(data) {
        alert(data);
        $("#someDiv").html(data);
    }
});
Sign up to request clarification or add additional context in comments.

2 Comments

You mean you want to replace the current loaded page with the search page via ajax?
exactly! i tried with Html.ActionLink, but i can't pass textbox value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.