In my parameters I have "Option" which are
-Gestion
-Colegio
-Estado
-Pais
I want to upload it to my DropDownList try in this way to load it but it's not like taking it into view, do you have any other method?
Controller:
public ActionResult Index()
{
List<SelectListItem> lst = new List<SelectListItem>();
lst.Add(new SelectListItem() { Text = "Gestion", Value = "1" });
lst.Add(new SelectListItem() { Text = "Colegio", Value = "2" });
lst.Add(new SelectListItem() { Text = "Estado", Value = "3" });
lst.Add(new SelectListItem() { Text = "Pais", Value = "4" });
ViewBag.Opciones = lst;
return View();
}
my view:
@model TNT.Controllers.ResumenParam
@{
ViewBag.Title = "Index";
}
@using (Html.BeginForm("Imprimir", "Resumen", new { id = "PDF" }, FormMethod.Post))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<div class="editor-field">
@Html.DropDownListFor(model => model.Gestion, Enumerable.Range(2000, 20).Select(x => new SelectListItem { Text = x.ToString() }))
@Html.ValidationMessageFor(model => model.Gestion)
</div>
<div class="editor-field">
@Html.DropDownList("Opcion", ViewBag.Opciones)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
Model:
public class CampoResumenColegioParam
{
// [Required(ErrorMessage = "Ingrese una Gestion")]
// [Display(Name = "Gestio")]
// [DataType(DataType.int)]
public int Gestion { get; set; }
public int Opciones { get; set; }
}