I am using Syncfusion.EJ2.Blazor nuget package in my project.
my country class:
public partial class Country
{
private ICollection<StateProvince> _stateProvinces;
/// <summary>
/// Gets or sets the entity identifier
/// </summary>
public int Id { get; set; }
/// <summary>
/// Gets or sets the name
/// </summary>
public string Name { get; set; }
/// <summary>
/// Gets or sets the two letter ISO code
/// </summary>
public string TwoLetterIsoCode { get; set; }
/// <summary>
/// Gets or sets the three letter ISO code
/// </summary>
public string ThreeLetterIsoCode { get; set; }
/// <summary>
/// Gets or sets the numeric ISO code
/// </summary>
public int NumericIsoCode { get; set; }
/// <summary>
/// Gets or sets the display order
/// </summary>
public int DisplayOrder { get; set; }
/// <summary>
/// Gets or sets the state/provinces
/// </summary>
public virtual ICollection<StateProvince> StateProvinces
{
get => _stateProvinces ?? (_stateProvinces = new List<StateProvince>());
protected set => _stateProvinces = value;
}
}
in my register Model i have public int? CountryId { get; set; }
so my service to return List of countries:
public async Task<IList<Country>> GetCountriesList()
{
var countries = await _context.Country
.OrderBy(b => b.Name)
.ToListAsync();
string sJSONResponse = JsonConvert.SerializeObject(countries);
return countries;
}
and my cshtml view:
@page
@model RegisterModel
@using Unfreighted.Services
@using Syncfusion.EJ2.Blazor.DropDowns
@using Syncfusion.EJ2.Blazor.Data
@inject CustomerService CustomerService
@{
ViewData["Title"] = "Register";
var data2 = CustomerService.GetCountriesList();
}
<div class="form-group">
<div class='content'>
<EjsAutoComplete TValue="string" Placeholder="e.g. Australia" DataSource="@data2.Result" Autofill=true>
<AutoCompleteFieldSettings Value="Name"></AutoCompleteFieldSettings>
</EjsAutoComplete>
</div>
</div>
But it is not doing anything. I use razor and chtml files together in my project.
1- How can I make this work?
2- How can I bind countryId to my model from autocomplete?