ddd
ddd

Reputation: 1399

How to post values outside a partial view to controller in ASP.NET MVC?

I am working with a paginated list like in the NerdDinner sample.

I am trying to show the navigation buttons for forward and back. I want there to be a form post when these are clicked so that the search text is still passed in. The problem is, the search text is stored in a form that is outside the partial view that the paged list is in and so the controller never finds it.

Any ideas on what I'm missing?

Upvotes: 1

Views: 514

Answers (3)

zihotki
zihotki

Reputation: 5191

google appends search text to the url, yahoo and msn too. I'm sure you can do the same and this is the better way :)

Upvotes: 0

Alexander Prokofyev
Alexander Prokofyev

Reputation: 34515

You could consider passing not only query results but also the search text to partial view via view model.

Upvotes: 1

eu-ge-ne
eu-ge-ne

Reputation: 28153

You can include

<input type="hidden" id="search" />

in the form with navigation buttons and fill it on POST using jQuery:

$(document).ready(function() {
    $('.yourNavButtonsClass').click(function () {
        var searchText = $('input#yourSearchTextBoxId').val();
        $('input#search').val(searchText);
    });
});

Unfortunately my solution requires Javascript/jQuery.

Upvotes: 0

Related Questions