1
I’m trying to get equal names off my dropdownlist, but they’re different id’s. I wanted where I would have to implant the code if it would be in the view, or in the controller somewhere else.
And this is what the dropdownlist looks like
This is my view:
@Html.ValidationMessageFor(a => a.NomeProdutoId)
@Html.LabelFor(a => a.NomeProdutoId, "Escolher Produto:")
@Html.DropDownListFor(a => a.NomeProdutoId, new SelectList(ViewBag.Compra, "Id", "NomeProduto"))
That is the line of code that the ViewBag.Compra
is pulling
public IList<Compra> Lista()
{
string hql = "select c from Compra c;";
IQuery query = session.CreateQuery(hql);
return query.List<Compra>();
}
On the part of
NomeId
would be what? For there is no such variable in the code– Guilherme Padovam
Same name. From what I understood of the table structure is that the Nomeid is the primary key of the Product Nomeid, right?
– Jean Gustavo Prates
Name is the user name that pulls from another table, I will try to put Id in place, it is the primary key
– Guilherme Padovam
Theoretically, you need to assign an Id to the Product name. It exists?
– Jean Gustavo Prates
No, then probably every product will have to have its ID in specific, correct?
– Guilherme Padovam
Exactly, instead of including the Product Name, you include the Product Idproduct. Soon, you will have a table with products that can be used more elegantly in the Dropdownlist (Without the need for Distinct).
– Jean Gustavo Prates
I understand, the problem that if I do this, this table where the product names and their values are, is ordered to other tables taking their products and values.
– Guilherme Padovam
Let’s go continue this discussion in chat.
– Jean Gustavo Prates