Set a default value in Dropdownlistfor

Asked

Viewed 76 times

0

In the form I have a:

@f.FormGroup().DropDownListFor(r => r.AtividadeId, Model.AtividadeList).WidthLg(6)  

listing all activities to perform a filter per activity.

I want to put an option: "List All" to list all activities without the filter. How I put this option and still leave as default?

On my model I put:

[Display(Name = "Atividade")]
[Required(ErrorMessage = "Campo obrigatório")]
public String AtividadeId { get; set; }
public SelectList AtividadeList { get; set; }

public IList<RelAtividadeVM> Atividade { get; set; }
  • I believe this is your answer, take a look (in English): https://stackoverflow.com/a/23799134/3456409

  • Thanks Marconcilio, but in the example you sent me he creates new lists. I already have a list that comes from BD, with all activities to be filtered, I need to add a value if the user chooses to send the report without filter.

  • @Rafaelchristófano If you have a property IList<RelAtividadeVM> Atividade and the SelectList AtividadeList, which is the one shown in the view... It means that at some point you are populating it, and so just start it with an empty and default item....

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.