I have a controller action which passes in a SQL query result to the view
[HttpGet]
[AllowAnonymous]
public IActionResult Register(string returnUrl = null)
{
var viewModel = new RegisterViewModel
{
Organisations = _context.Organisations.ToList(),
};
ViewData["ReturnUrl"] = returnUrl;
return View(viewModel);
}
The view is a registration page which asks for the users email address. I want the email address to autofill with the domain relevant to their organisation after they type "@" - this is facilitated by jquery.email-autocomplete.js - Example image of input field in use: here
There are about 50 organisations and they are stored in a database table which is structured like:
ID | Name | EmailDomain
-----------------------------------
1 My Org myorganisation.co.uk
I need a way to dynamically get the email domains from the organisation object into this bit of jquery code in the view:
<script>
$("#email").emailautocomplete({
suggClass: "custom-classname", //default: "eac-sugg". your custom classname (optional)
domains: ["example.com"] //additional domains (optional)
});
</script>
So when rendered, the line of code for domains needs to look something like:
domains: ["myorganisation.co.uk", "anotherorganisation.org.uk", "andanother.com"]