views:

38

answers:

1

I am correctly passing the action name from the Controller to the paging class and then using select list i want to redirect to that action. at this moment it is appending to the current url.i want the correct way of redirecting to the controller action manageUser using select list below

What should we have here in Model.COntroller . ControllerName/ActionName/ or Just ActionName

 <select id="paging" onchange="location.href='<%= Model.Controller %>'+this.value">

     <% for (int i = 1; i <= Model.TotalPages; i++)
      {  %>
         <option id=<%=i %>><%=i %></option>
     <% } %>
    </select>


public class PaginatedList<T> : List<T>
{

    public string Controller { get; private set; }

    public PaginatedList(IQueryable<T> source, int pageIndex, int pageSize,string Cont)
    {
        Controller = Cont;                   // here is the controller 

    }
  }

Controller
    public ActionResult ManageUser(int? page)
    {
        const int pageSize = 5;
        var AllUser = UserRepository.GetAllUser();
        var paginatedUsers = new PaginatedList<Users>(AllUser, page ?? 1, pageSize,"ManageUser/Page/");

        return View(paginatedUsers);
    }
+1  A: 

I would probably set the value of the select to the url you want to redirect to. That way you can still use the built-in helpers to generate your urls. Something like this:

<select id="paging" onchange="location.href=this.value">
 <% for (int i = 1; i <= Model.TotalPages; i++)
  {  %>
     <option value="<%=Url.Action("ActionName", "ControllerName", new { page = i })%>"><%=i %></option>
 <% } %>
</select>
Mattias Jakobsson
Works Wonderfully well
mazhar kaunain baig