andrey1567
andrey1567

Reputation: 129

Create dropdownlist with numbers 1 to 30 mvc

I need create dropdownlist with numbers 1 to 30 . and to transfer this number to another view, where I need to show it. Thanks

View (Index)

@Html.BeginForm()
{
//this I need DropdownList with numbers from 1 to 30
<input type = "submit" >Enter/>
}

[HttpPost]

        public ActionResult Index()
        {
            return RedirectToAction("SecondView");
        }

How I display number in "SecondView"?

Upvotes: 2

Views: 6051

Answers (2)

AliHesam
AliHesam

Reputation: 61

@Html.DropDownListFor(m => m.WorkExperienceTime, Enumerable.Range(1, 30).Select(i => new SelectListItem { Text = i.ToString(), Value = i.ToString() }),new { placeholder= Html.DisplayNameFor(x => x.WorkExperienceTime), @class = "form-control" } )

Upvotes: 6

Mahedi Sabuj
Mahedi Sabuj

Reputation: 2944

Try this...

Controller

var list = new List<SelectListItem>();
for (var i = 1; i < 31; i++)
    list.Add(new SelectListItem { Text = i.ToString(), Value =    i.ToString() });
ViewBag.list = list;
return View();

View

@using(Html.BeginForm())
{
    @Html.DropDownList("drp", new SelectList(ViewBag.list, "Text", "Value"),  "Select")
   <input type="submit">
}

Upvotes: 2

Related Questions