.NET MVC - View Lists and Details

I think there is a simple answer to this question, but for some reason, today I hit the block of writers. I have an application that people can search for (for example, any application :)) and create a list view. From this list you can view information that will lead you to a detailed presentation. No JS, just another page. But, what I would like to do is have the back / next button in the detail view so that you can analyze the result set without returning to the list, and then select the next record.

I had two ideas for achieving this. Idea 1) I have the next / previous record field in my class. However, this will not work, as the search query will not necessarily return consistent results, and I will have to query DB each time to get these next / previous lists. Idea 2) Have a list of identifiers or some user object passed in the view state for each view corresponding to the search results. I’m not sure about the “overhead” associated with this method.

Any suggestions from the SO community?

Thank!

+3
source share
1 answer

, , , / , . , , , foreach, - / . , .

/ - , / . "" , URL-, URL-. , , / .

<% for (int i = 0, len = Model.Count(); i < len; ++i)
   {
      Foo model = Model.ElementAt(i);
      string prev  = i == 0 ? null : string.Join( ",", Model.Take(i).Select( m => m.ID.ToString() ).ToArray() );
      string next = i == (len - 1) ? null : string.Join( ",", Model.Skip(i).Select( m => m.ID.ToString() ).ToArray() )
 %>
   <% using (Html.BeginForm("Details","Bar", new { id = model.ID } )) { %>
        <%= Html.AntiForgeryToken() %>
        <%= Html.Hidden( "Prev", prev ) %>
        <%= Html.Hidden( "Next", next ) %>
        <input type="submit" value="Details" />
   <% } %>
<% } %>

, , jQuery, , , .

+1

Source: https://habr.com/ru/post/1736141/


All Articles