Our system has a set of known "Contract Types" which have a code and a name.
public struct ContractType {
public string Code { get; set; }
public string Name { get; set; }
}
I have an MVC controller with a method like this.
[HttpGet]
public ActionResult Search(SearchOptions options) {
// returns search results
}
SearchOptions
contains many parameters (including an array of ContractType
)
public class SearchOptions {
public ContractTypes[] Contracts { get; set; }
// other properties
}
I would like asp.net MVC to automatically translate the contract type codes into an array of contract types on the SearchOptions
model. For example, I want the MVC model binder to take a a querystring like this...
http://abc.com/search?contracts=ABC&contracts=XYZ&foo=bar
and populate SearchOptions
so that it looks like the following data structure
{
Contracts : [
{ Code : "ABC", Name: "ABC Contract Name" },
{ Code : "XYZ", Name: "XYZ Contract Name" }
],
// other properties
}
I have a method available which will accept a contract type code and return the appropriate ContractType.
public ContractType GetContractTypeByCode(string code) {
// code which returns a ContractType
}
I am not clear on whether I need to be using a custom model binder or a value provider. Any help is appreciated.