Reputation: 282
In my controller I have
var myTempModel = (from f in db.BA_TEMP_RESHOP_IMPORT
where f.WCCR_ID == WccrId
select new DataImportViewModel
{
//Set properties…
});
return View(myTempModel.ToPagedList(currentPage,
maxRecords));
Any my current ViewModel
public class DataImportViewModel
{
public string WccrId { get; set; }
public string Status { get; set; }
public string Note { get; set; }
}
My view model reference is.
@model PagedList.IPagedList<Proj.ViewModels.DataImportViewModel>
Each item is using displayFor. This works fine, but now I need to add a checkbox that retains it's value across the pagination
I want to add a single checkbox to the top of the page, not applied to each row returned from the DataImportViewModel.
I figure that there are two ways to do this, but not sure how to implement either nor am I sure which is the best. Is it better to create a new viewModel or pass the checkbox value into a session variable?
I tried creating a new viewmodel such as this, but can’t figure out how to change my return View(…) code, or even what I should use for @model in the view.
public class DisplayViewModel
{
public IEnumerable<DataImportViewModel> dataImport { get; set; }
public Boolean useDefault { get; set; }
}
Thanks in advance for your help. Please let me know if there is any information that is helpful that I might have left out. cheers
Upvotes: 2
Views: 1902
Reputation: 1082
I've done something similar:
Exetnd your PagedList entity ( i suppose thats where you store data like page number, nr of records per page , sorting direction , etc ) with a boolean field ... When you pass the nr of the page you're in ... you will also send the bool version back to the controller so that way you will be able to pass the value to the checkbox.
Don;t forget to update the target div ( targetdiv= the div where your entity is displaied within your view ) .
My solution involved something like this :
public class GridModel<T> : GridOperations
{
// Constructor
public GridModel()
{
// Define any default values here...
this.PageSize = 20;
this.NumericPageCount = 20;
}
public IEnumerable<T> Data { get; set; }
and passted data to my model as follows:
@model Proj.ViewModels.GridModel<Proj.ViewModels.DataImportViewModel>
and within the Grid operations class i've implemented many values that are complementary ( such as a string for a search textbox , status : active/not active ... etc) along with the ones you see ( pagesize,numericpagecount,sorting direction, sortBy,etc) . From my point of view this makes more sense .. but I might be biased :) . If you cannot pass that value within your DataImportViewModel, I suggest you modify towards my grid thinking
Upvotes: 2