Monday, 23 November 2015

Static Dropdown list with default value in mvc

         Create

//Controller

 var list = new SelectList(new[]
            {
                new { ID = "-Select-", Name = "-Select-" },
                new { ID = "Hourly",  Name = "Hourly" },
                new { ID = "Monthly",  Name = "Monthly" },
                new { ID = "Semi Monthly",  Name = "Semi Monthly" },
                new { ID = "Weekly",  Name = "Weekly" },

            },
                "ID", "Name", 1);

 ViewBag.StatID = list;


//View

 @Html.DropDownList("StatID", null, "-Select-",new { @class = "form-control" })

Edit

//controll


 var list = new SelectList(new[] 
            {
                new { ID = " Bi Weekly", Name = "Bi Weekly" },
                new { ID = "Daily", Name = "Daily" },
                new { ID = "Hourly",  Name = "Hourly" },
                new { ID = "Monthly",  Name = "Monthly" },
                new { ID = "Semi Monthly",  Name = "Semi Monthly" },
                new { ID = "Weekly",  Name = "Weekly" },

            },
            "ID", "Name", tbl_EmployeeSalary.PayValue);

            ViewBag.StatID = list;

//view

@Html.DropDownList("StatID", null, htmlAttributes: new { @class = "form-control" })

Create and edit functions pass one parameter like string StatID


No comments:

Post a Comment