{"id":592,"date":"2021-11-26T17:06:00","date_gmt":"2021-11-26T08:06:00","guid":{"rendered":"https:\/\/mvc.auctionpro.co.kr\/?page_id=592"},"modified":"2021-11-26T18:05:27","modified_gmt":"2021-11-26T09:05:27","slug":"select-options-%eb%94%94%eb%b9%84%ec%97%90%ec%84%9c-%ea%b0%80%ec%a0%b8%ec%98%a4%ea%b8%b0","status":"publish","type":"page","link":"https:\/\/mvc.auctionpro.co.kr\/?page_id=592","title":{"rendered":"select options \ub514\ube44\uc5d0\uc11c \uac00\uc838\uc624\uae30"},"content":{"rendered":"\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:c# decode:true \" title=\"Controller\">::: \uc911\ub7b5 :::\t\t\nnamespace MVCTEST.Controllers\n{\n    public class TestController : Controller\n    {\n        private readonly DBContext _context;\n\n        public TestController(DBContext context)\n        {\n            _context = context;\n        }\n\n        [BindProperty]\n        public List&lt;SelectListItem&gt; Options { get; set; }\n\n        \/\/ GET\n        public async Task&lt;IActionResult&gt; Index(\n               int? id,\n               string Title_Search)\n               \n\t\t{\n\t\t\t::: \uc911\ub7b5 :::\n\t\t\t\n\t\t\t\/\/\uce74\ud14c\uace0\ub9ac\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n            Options = _context.DBTestTable.Select(a =&gt;\n                                                  new SelectListItem\n                                                  {\n                                                      Value = a.NUM.ToString(),\n                                                      Text = a.NAME.ToString(),\n                                                      Selected = false\n                                                  }).ToList();\n\n            Options.Insert(0, new SelectListItem()\n            {\n                Text = \"\uc804\uccb4 \uce74\ud14c\uace0\ub9ac\",\n                Value = string.Empty\n            });\n\n            foreach (var item in Options)\n            {\n                if (item.Value == Title_Search)\n                {\n                    item.Selected = true;\n                    break;\n                }\n            }\n\n            ViewData[\"Options\"] = Options;\n\n\t   return View();\t\n\t\t}\n\t}\n}<\/pre><\/div>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:c# decode:true \" >@Html.DropDownList(\"Title_Search\", ViewBag.Options as IEnumerable&lt;SelectListItem&gt;)\n\n\n@Html.DropDownList(\"Title_Search\", ViewBag.Options as IEnumerable&lt;SelectListItem&gt;,new {onchange=\"this.form.submit();\"})<\/pre><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-592","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/mvc.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/pages\/592","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mvc.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/mvc.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/mvc.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mvc.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=592"}],"version-history":[{"count":2,"href":"https:\/\/mvc.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/pages\/592\/revisions"}],"predecessor-version":[{"id":596,"href":"https:\/\/mvc.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/pages\/592\/revisions\/596"}],"wp:attachment":[{"href":"https:\/\/mvc.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=592"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}