c# - ASP.NET MVC multiple parameters and models -
description: have model workorder
contains workorderform
model (start_date, end_date, organization
), list of models (the actual orders) , page parameters (page, page_size, page_count
). main idea display work orders, , because there large amount of them have filter data; work orders pulled database server (not local). on initial view prompt start_date
, end_date
, use datatype.date
, organization
use string
, information get's stored in model pass in httppost
. extracts data , displays it. now, because there lot of orders, made costume pages sort data, , use 2 variables, page
, page_size
, displayed , can set on view after valid workorderform
submitted.
problem: problem facing right can't seem pass 2 parameters page
, page_size
, view controller @ same time. both of them work seem reset each other, example: on page
4, set page_size
20 50, , resets page
1, 1 alright, main on when chose page
, reset page_size
default (20). submitting has happen inside html.beginform() otherwise lose information stored in model.
edit: using pagedlist.
new problem: when select page calls [httpget]
, resetting model , page size. tried implement in index, failed miserably.
workorder:
public class workorder { [key] public int id { get; set; } public ipagedlist<mymodel> view_list { get; set; } public workorderform work_form { get; set; } }
controller:
[httpget] public actionresult index(workorder model) { var list = new list<mymodel>(); model.view_list = list.topagedlist(1,1); return view(model); } [httppost] public actionresult index(workorder model, int? page, int? page_size, string start_date, string end_date, string org) { var list = new list<mymodel>(); if (modelstate.isvalid) { using (oracledbctx ctx = new oracledbctx()) { //database stuff int pagenumber = (page ?? 1); int pagesize = (page_size ?? 20); model.view_list = list.topagedlist(pagenumber, pagesize); return view(model); } } modelstate.addmodelerror("", "incorrect information submitted"); return view(); }
page info submission in view:
@:page @(model.view_list.pagecount < model.view_list.pagenumber ? 0 : model.view_list.pagenumber) of @model.view_list.pagecount @html.pagedlistpager(model.view_list, page => url.action("index", "workorder", new { page, viewbag.page_size, start_date = model.work_form.start_date, end_date = model.work_form.end_date, org = model.work_form.org }));
question: how go passing both of parameters view , @ same time keep model information, if choosing update 1 parameter? if have suggestions on possible work around's happy hear ideas, pointing me in direction appreciated. if there might missing please say.
new question: how ether pagedlist call [httppost] index, or whats best way implement in default index controller?
following implementation of index in controller worked
public actionresult index(workorder model, int? page, int? page_size, string start_date, string end_date, string org) { if (model.work_form == null) { if (start_date != null && end_date != null && org != null) { var form = new workorderform { start_date = start_date, end_date = end_date, org = org }; model.work_form = form; } } if (model.work_form != null) { using (oracledbctx ctx = new oracledbctx()) { //do database stuff //var list = database(query).tolist() int pagenumber = (page ?? 1); int pagesize = (page_size ?? 20); int count = list.count; if (pagenumber - 1 > count / page_size) { pagenumber = 1; } model.view_list = list.topagedlist(pagenumber, pagesize); return view(model); } } return view(); }
Comments
Post a Comment