Skip to content

Instantly share code, notes, and snippets.

@jmkelly
Created July 12, 2011 23:54
Show Gist options
  • Save jmkelly/1079460 to your computer and use it in GitHub Desktop.
Save jmkelly/1079460 to your computer and use it in GitHub Desktop.
Multiple responses based on request type
public class CountryModel
{
public string Code { get; set; }
public string Name { get; set; }
}
public class CountrieslistHandler
{
public IResult Get()
{
// In real life, maybe this list will come from some service call that just gives you back the List<T>.
var countries = new List<CountryModel>
{
new CountryModel { Code = "AF", Name = "Afghanistan" },
new CountryModel { Code = "AO", Name = "Angola" },
new CountryModel { Code = "BY", Name = "Belarus" },
new CountryModel { Code = "FR", Name = "France" },
};
//this is pseudo code, not sure what the actual methods / properties are...
if (request.type = "json"){
return Result.Json(countries);
}
if (request.type = "html")
{
return View.Spark(countries, "View/Counties.spark");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment