Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC3 Binding a custom Collection
    primarykey
    data
    text
    <p>As per : <a href="https://stackoverflow.com/questions/8759244/mvc3-model-binding-pagedlist-to-viewmodel-with-custom-editortemplate-and-partial">MVC3 Model binding pagedlist to ViewModel with custom EditorTemplate and Partial View</a></p> <p>See above question for code snippets</p> <p>The problem i am having now surrounds binding the custom IPagedList collection. The model binder attempts to bind the values to the property on the ViewModel but is unable to create an instance of the interface (no suprises there).</p> <p>So how can i bind values back to my viewModel by instantiating a concrete PagedList class when the values are bound? As i understand it the IEnumerable binder does this for a List or similar derivitive, so how can i do this for my custom class/interface?</p> <p>Do i need a custom model binder for this? If so any information or code tips on this is great!</p> <p>Any help greatly appreciated thanks.</p> <p>Update:</p> <p>Changing the ViewModel to include an overriden default constructor which initialises the Interface like so:</p> <pre><code>public class RequestCreateViewModel : ViewModelBase { public IPagedList&lt;CreateRequestModel&gt; PagedList { get; set; } public RequestCreateVieWModel() { PagedList = new PagedList&lt;RequestCreateModel&gt;(new List&lt;RequestCreateModel&gt;(), new PagingOptions()); } </code></pre> <p>.. appears to allow the default model binder to work as per my comment. But it doesnt seem like a great solution, mainly because im needing to infer new object parameters for the PagedList object each time a ViewModel is created. Am i needlessly worrying?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload