Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jun 04, 2010 04:32 PM by jerrolds
Member
95 Points
123 Posts
Jun 04, 2010 04:11 PM|LINK
I'm trying to implement paging in my app, so i need to know what page the user wants to click on, as well as pass the model (for some fields)
I'm able to pass the desired page, just not the model (for the search criteria)
here is my view:
<% if (Model.PageCount > 0) {%> <% for(int i=1; i<=Model.PageCount; i++) {%> <%= Html.ActionLink(i.ToString(), "NextPage", new { searchModel = Model, pageIndex = i}) %> <% }%> <% }%>
Heres my Controller Action
public ActionResult NextPage(SearchResults searchModel, int pageIndex) { SearchResults results = _searchService.Search(model.Search, pageIndex, PAGE_SIZE); return View("Index", results); }
My ViewModel SearchResults has a string property "Search". When i do it this way searchModel == null in the NextPage Action. Thanks for any help.
Contributor
4291 Points
1352 Posts
Jun 04, 2010 04:22 PM|LINK
LOL..I broke my head on this one before as well, until I learned it don't work that way.
Turned out "best" way is storing your model in the TempData (and I don't like that either)
You could have a look at this solution for one.
Jun 04, 2010 04:32 PM|LINK
Ugh. Haha so basically there is no model binding when you wanna pass in other parameters?
I got it working thanks to the post you linked
Heres the View:
<% if (Model.PageInfo.PageSize > 1) {%> <% for(int i=1; i<=Model.PageInfo.PageSize; i++) {%> <%= Html.ActionLink(i.ToString(), "NextPage", new { search = Model.Search, pageIndex = i })%> <% }%> <% }%>
My Controller:
public ActionResult NextPage(string search, int pageIndex) { SearchResults results = _searchService.Search(search, pageIndex, PAGE_SIZE); return View("Index", results); }
Thanks much!
Jerrolds
Member
95 Points
123 Posts
Friday Stupidness Part 2 - cannot pass model to action via ActionLink?
Jun 04, 2010 04:11 PM|LINK
I'm trying to implement paging in my app, so i need to know what page the user wants to click on, as well as pass the model (for some fields)
I'm able to pass the desired page, just not the model (for the search criteria)
here is my view:
<% if (Model.PageCount > 0) {%> <% for(int i=1; i<=Model.PageCount; i++) {%> <%= Html.ActionLink(i.ToString(), "NextPage", new { searchModel = Model, pageIndex = i}) %> <% }%> <% }%>Heres my Controller Action
public ActionResult NextPage(SearchResults searchModel, int pageIndex) { SearchResults results = _searchService.Search(model.Search, pageIndex, PAGE_SIZE); return View("Index", results); }My ViewModel SearchResults has a string property "Search". When i do it this way searchModel == null in the NextPage Action. Thanks for any help.
krokonoster
Contributor
4291 Points
1352 Posts
Re: Friday Stupidness Part 2 - cannot pass model to action via ActionLink?
Jun 04, 2010 04:22 PM|LINK
LOL..I broke my head on this one before as well, until I learned it don't work that way.
Turned out "best" way is storing your model in the TempData (and I don't like that either)
You could have a look at this solution for one.
Jerrolds
Member
95 Points
123 Posts
Re: Friday Stupidness Part 2 - cannot pass model to action via ActionLink?
Jun 04, 2010 04:32 PM|LINK
Ugh. Haha so basically there is no model binding when you wanna pass in other parameters?
I got it working thanks to the post you linked
Heres the View:
<% if (Model.PageInfo.PageSize > 1) {%> <% for(int i=1; i<=Model.PageInfo.PageSize; i++) {%> <%= Html.ActionLink(i.ToString(), "NextPage", new { search = Model.Search, pageIndex = i })%> <% }%> <% }%>My Controller:
public ActionResult NextPage(string search, int pageIndex) { SearchResults results = _searchService.Search(search, pageIndex, PAGE_SIZE); return View("Index", results); }Thanks much!