I'm trying to get the StatusId of the selected item in my list.
I have a list of status created with Material Design Lite:
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label getmdl-select getmdl-select__fix-height">
<input type="text" value="" class="mdl-textfield__input" id="statusList" asp-for="Status" readonly>
<input type="hidden" value="" name="statusList" asp-for="StatusId">
<i class="mdl-icon-toggle__label material-icons">keyboard_arrow_down</i>
<label for="statusList" class="mdl-textfield__label">Status</label>
<ul for="statusList" class="mdl-menu mdl-menu--bottom-left mdl-js-menu">
@foreach (var status in ViewBag.Status)
{
<li class="mdl-menu__item" data-val="@status.Id">@status.Name</li>
}
</ul>
</div>
I set the StatusId here:
<li class="mdl-menu__item" data-val="@status.Id">@status.Name</li>
And I noticed that the StatusId go to this input when I select an item in the list:
<input type="hidden" value="" name="statusList" asp-for="StatusId">
I added asp-for in it but it is not working. The value in the Controller after the submit is ZERO.
The asp-for="Status" in the following input works perfeclty and the bind to the Controller occurs perfectly:
<input type="text" value="" class="mdl-textfield__input" id="statusList" asp-for="Status" readonly>
Controller method:
public async Task<IActionResult> Create([Bind("StatusId,CNPJ,Name,BusinessName,State,City,Street,District,CEP,Observation,Phone,Cellphone,Email,Status")] Company company)
{}
CompanyStatus model:
public class CompanyStatus
{
public int Id { get; set; }
public string Name { get; set; }
}
Company model:
public class Company
{
public int Id { get; set; }
public int StatusId { get; set; }
public string CNPJ { get; set; }
public string Name { get; set; }
public string BusinessName { get; set; }
public string State { get; set; }
public string City { get; set; }
public string Street { get; set; }
public string District { get; set; }
public string CEP { get; set; }
public string Observation { get; set; }
public string Phone { get; set; }
public string Cellphone { get; set; }
public string Email { get; set; }
public string Status { get; set; }
}
Any ideas what I am doing wrong?

status.Idis not the same asStatusId. What does your model type look like?""– Do you ever change that value on the client side? Otherwise, it will stay empty, and the empty value will be deserialized into the default value forintwhich is zero.