-
-
Save jmkelly/1079460 to your computer and use it in GitHub Desktop.
Multiple responses based on request type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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