You must Sign In to post a response.
  • Category: ASP.Net MVC

    How to get partial view when button clicks

    Hi,

    How to get partial view when button clicks in mvc
  • #765577
    Hi Dinesh,

    Try out below code snippet.

    Inside html :
    <button id="search">Search</button>

    Add the following script

    var url = '@Url.Action("DisplaySearchResults", "Search")';
    $('#search').click(function() {
    var keyWord = $('#Keyword').val();
    $('#searchResults').load(url, { searchText: keyWord });
    });

    Controller method to accept the search text

    public ActionResult DisplaySearchResults(string searchText)
    {
    var model = // build list based on parameter searchText
    return PartialView("SearchResults", model);
    }

    Hope it helps!!!

  • #765637
    If its a simple view without data then you can try this,

    $('#btnClick').click(function() {
    $('#divId').load('/shared/PartialView');
    });

  • #765650
    There are two ways. One you can directly call the @Url.Action with will bring you partial view into your main view.
    This will happen in the page load itself. I you want to process some calculation based on the button click the want to show the partial view. then you can go for simple Jquery Ajax call. In the Ajax call you can process your calculation and show your partial view.

    By Nathan
    Direction is important than speed


Sign In to post your comments