Search code examples
asp.net-coremodel-view-controllerpartial-viewsnopcommerce

How do I render my partialview inside my main view or can I update the values in another way?


I have the following problem: So I built a search function for an OrderId in Nopcommerce and I want to update two values (Buyer Name) and (Purchase Reason) in a table in my main view instead of how it is now, where I render them in a partial view but it appears on the main page.

Example:

My search field, after I click search I want the result to appear below it without loading a new page

How it is at the moment after I click search button :

It pops up a new window with the results. Basically I want this panel here to appear in my first view as I explained earlier

My controller that renders the partial view:

I think I need to change something here right?

And here:Part of my SearchResult.cshtml partial view where the values appear

Part of my SearchResult.cshtml partial view where the values appear

I want it to appear somewhere here (My startview.cshtml as you can see I tried some things but nothing seems to work, Ill delete those) I want it to appear somewhere here (My startview.cshtml as you can see I tried some things but nothing seems to work, Ill delete those)

Thank you in advance!


Solution

  • You can achieve this using ajax call.

                var request = {
                    OrderId: $('#OrderId').val(),
                }
                $.ajax({
                    url: "/Home/DisplayBuyerName",
                    type: "GET",
                    data: request,
                    contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
                    success: function (data) {
                        $("#SearchResult").html('').html(data);
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        alert(errorThrown);
                        return false;
                    }
                });
    

    html:

    <div id="SearchResult"> </div>
    

    So now your partial view is placed in SearchResult div.