Skip to content

Instantly share code, notes, and snippets.

@ad-m
Last active September 4, 2017 22:57
Show Gist options
  • Select an option

  • Save ad-m/21ba1d607cf9a34dd1c6a284db5e2520 to your computer and use it in GitHub Desktop.

Select an option

Save ad-m/21ba1d607cf9a34dd1c6a284db5e2520 to your computer and use it in GitHub Desktop.
ASP.Net Cheatsheet
// both POST and GET
ViewBag.SaleSelect = new SelectList(db.Salas, "ID", "NrSali");
[Required]
public int SalaId { get; set; }
[Display(Name = "Sala")]
public virtual Sala Sala { get; set; }
<div class="form-group">
@Html.LabelFor(model => model.Sala, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(x => x.SalaId, (IEnumerable<SelectListItem>)ViewBag.SaleSelect, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Sala, "", new { @class = "text-danger" })
</div>
</div>
@Html.TextAreaFor(model => model.Abstrakt, new { @class = "form-control" })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment