2
I would like to create a Dropdown dependent on another Dropdown in C#, ASP.net - MVC 5, in case it would be a dropdown with the names of all customers and then another Dropdown with the phones of the Customer selected in the first Dropdown. How to do?
Class : Request
public class Pedido
{
public Pedido()
{
this.Produtos = new List<Produto>();
}
[Key]
public int PedidoID { get; set; }
public Cliente Cliente { get; set; }
[Display(Name = "Nome do Cliente")]
public int ClienteID { get; set; }
[Display(Name = "Telefone")]
public string ClienteFone { get; set; }
[Display(Name = "Cidade")]
public string ClienteCidade { get; set; }
[Display(Name = "Estado")]
public string ClienteEstado { get; set; }
[Display(Name = "Endereço")]
public string ClienteEndereço { get; set; }
public ICollection<Produto> Produtos { get; set; }
[Display(Name = "Status to pedido")]
public Estatus Estatus { get; set; }
public int EstatusID { get; set; }
[Display (Name="Data do pedido")]
public DateTime DataPedido { get; set; }
}
Create.cshtml
@Html.ValidationSummary(true)
<div class="form-group">
@Html.LabelFor(model => model.ClienteID, "ClienteID", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("ClienteID", String.Empty)
@Html.ValidationMessageFor(model => model.ClienteID)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ClienteFone, "ClienteFone", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("ClienteFone", String.Empty)
@* @Html.EditorFor(model => model.ClienteFone)*@
@Html.ValidationMessageFor(model => model.ClienteFone)
</div>
</div>
I’m having trouble putting the id’s in the dropdowns, that’s how it is?
– user3014578
What kind of problem?
– Diego Vieira
I am not receiving the value of the second dropdown to register in the bank, when I select the client I view the phones but it is not running by the Create method in my controller
– user3014578
This is because of the "bind" that MVC makes with the data, forget creating with Razor and do
<select id="clienteFone" name="clienteFone"></select>
Probably now it should pass.– Diego Vieira