Created
February 17, 2016 23:42
-
-
Save cpoDesign/0cc0a3c0b0fe457e3807 to your computer and use it in GitHub Desktop.
Example of implementation of @Html.DropDownListFor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DemoController : Controller | |
{ | |
public ActionResult Index() | |
{ | |
var model = new DemoModel(); | |
model.Items = new List<SelectListItem>() | |
{ | |
new SelectListItem() | |
{ | |
Text = "one", | |
Value = "1", | |
Selected = false | |
}, | |
new SelectListItem() | |
{ | |
Text = "two", | |
Value = "2", | |
Selected = true | |
} | |
}; | |
return View(model); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DemoController : Controller | |
{ | |
public ActionResult Index() | |
{ | |
var model = new DemoModel(); | |
model.Items = new List<SelectListItem>() | |
{ | |
new SelectListItem() | |
{ | |
Text = "one", | |
Value = "1" | |
}, | |
new SelectListItem() | |
{ | |
Text = "two", | |
Value = "2" | |
} | |
}; | |
model.ItemValue = 2; | |
return View(model); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DemoModel | |
{ | |
public IEnumerable<SelectListItem> Items { get; set; } | |
public int ItemValue { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@model YourNameSpace.DemoModel | |
@Html.DropDownListFor(x=>x.ItemValue,Model.Items) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@model YourNameSpace.DemoModel | |
@Html.DropDownListFor(x=>x.ItemValue, new SelectList(Model.Items,"Value","Text")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment