I have two classes that contain data only (Settings and Credentials). I don't know how I should call these classes so bear with me.
Example of data classes.
class Settings
{
public string Host { get; set; }
public int Port { get; set; }
}
class Credentials
{
public string UserName { get; set; }
public string Password { get; set; }
}
I want to create a new object containing these two data classes using a MVC controller action.
Example of object class.
class Object
{
private readonly Settings _settings;
private readonly Credentials _credentials;
public Object(Settings settings, Credentials credentials)
{
_settings = settings;
_credentials = credentials;
}
}
Example for what I'm trying to do.
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
[HttpPost]
public IActionResult Create(Settings settings, Credentials credentials)
{
new Object(settings, credentials);
return View(Index());
}
}
My question how can I achieve this is a nice manner? Without having to put every single parameter in the IActionResult Create() method.
And what should my POST form look like?
Thanks.