{"id":1823,"date":"2017-01-30T23:04:01","date_gmt":"2017-01-30T14:04:01","guid":{"rendered":"http:\/\/elink.tokyo\/?p=412"},"modified":"2017-09-17T00:06:22","modified_gmt":"2017-09-16T15:06:22","slug":"html-checkboxfor","status":"publish","type":"post","link":"https:\/\/greentown.tokyo\/?p=1823","title":{"rendered":"@Html.CheckBoxFor\u306e\u5024\u3092Request.Form.Get()\u3067\u53d6\u5f97\u3059\u308b"},"content":{"rendered":"<p>@Html.CheckBoxFor\u306e\u5024\u3092Request.Form.Get()\u3067\u53d6\u308a\u305f\u304b\u3063\u305f\u3093\u3067\u3059\u304c<\/p>\n<pre class=\"lang:c# decode:true\" title=\"View\">&lt;td&gt;\r\n  @Html.CheckBoxFor(m =&gt; itm.blEnabled\r\n&lt;\/td&gt;<\/pre>\n<p>\u3053\u3046\u66f8\u3044\u3066<\/p>\n<p>\u30b5\u30fc\u30d0\u3067<\/p>\n<pre class=\"lang:asp decode:true\" title=\"Controller\">[HttpPost]\r\npublic ActionResult Save()\r\n{\r\n    string[] enabled = Request.Form.Get(\"itm.blEnabled\").Split(',');<\/pre>\n<p>\u3053\u3046\u3084\u308b\u3068<\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-414 size-full\" src=\"http:\/\/elink.tokyo\/wp-content\/uploads\/2017\/01\/chkboxfor.png\" width=\"186\" height=\"215\" \/><\/p>\n<p>9\u884c\u3057\u304b\u306a\u3044\u306e\u306b\u3001\u306a\u305c\u304b12\u4ef6\u30fb\u30fb\u30fb\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u30c7\u30d9\u30ed\u30c3\u30d1\u30fc\u30c4\u30fc\u30eb\u3067\u78ba\u8a8d<\/h2>\n<p>\u751f\u6210\u3055\u308c\u305fhtml\u30b3\u30fc\u30c9\u3092\u307f\u308b\u3068<\/p>\n<pre class=\"lang:default decode:true\" title=\"html\">&lt;td&gt;\r\n  &lt;input checked=\"checked\" data-val=\"true\" id=\"itm_blEnabled\" name=\"itm.blEnabled\" type=\"checkbox\" value=\"true\"&gt;\r\n  &lt;input name=\"itm.blEnabled\" type=\"hidden\" value=\"false\"&gt;\r\n&lt;\/td&gt;<\/pre>\n<p>\u3068\u306a\u3063\u3066\u3044\u305f\u3002<\/p>\n<p>\u300citm.blEnabled\u300d\u3092\u691c\u7d22\u3059\u308b\u306818\u4ef6\u30d2\u30c3\u30c8\u3002<\/p>\n<p>checkbox\u3068hidden\u306ename\u5c5e\u6027\u304c\u91cd\u306a\u3063\u3066\u3001\u5024\u304c\u3054\u3061\u3083\u6df7\u305c\u306b\u306a\u3063\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>checkbox\u3068hidden\u306ename\u5c5e\u6027\u304c\u91cd\u306a\u3089\u306a\u3044\u3088\u3046\u306b\u3059\u308b<\/h2>\n<p>View\u306e\u5c5e\u6027\u3092\u4fee\u6b63<\/p>\n<pre class=\"lang:asp decode:true\" title=\"View\">&lt;td id=\"tdChBox\"&gt;\r\n  @Html.CheckBoxFor(m =&gt; itm.blEnabled, new { id = \"chEnabled\", Name = \"chEnabled\" })\r\n&lt;\/td&gt;<\/pre>\n<p>\u5909\u66f4\u70b9<\/p>\n<ol>\n<li>&lt;td&gt;\u30bf\u30b0\u306bid\u5c5e\u6027\u3092\u8ffd\u52a0\uff08\u30c1\u30a7\u30c3\u30afoff\/on\u7528\u306b\u4f7f\u7528\uff09<br \/>\n<span style=\"color: #ff0000;\">id=&#8221;tdChBox&#8221;<\/span><\/li>\n<li>checkbox\u3068hidden\u306e\u5c5e\u6027\u304c\u7af6\u5408\u3057\u306a\u3044\u3088\u3046\u306b\u3001checkbox\u306eid\u3068name\u3092\u5225\u540d\u524d\u306b\u3059\u308b<br \/>\n<span style=\"color: #ff0000;\">new { id = &#8220;chEnabled&#8221;, Name = &#8220;chEnabled&#8221; }<\/span><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>\u5909\u66f4\u5f8c\u3001\u751f\u6210\u3055\u308c\u305fView<\/p>\n<pre class=\"lang:asp decode:true\" title=\"View\">&lt;td id=\"tdChBox\"&gt;\r\n  &lt;input name=\"chEnabled\" checked=\"checked\" data-val=\"true\" id=\"chEnabled\" type=\"checkbox\" value=\"true\"&gt;\r\n  &lt;input name=\"itm.blEnabled\" type=\"hidden\" value=\"true\"&gt;\r\n&lt;\/td&gt;<\/pre>\n<p>&nbsp;<\/p>\n<h2>JavaScript\u3067\u8abf\u6574<\/h2>\n<h3>\u521d\u671f\u8868\u793a<\/h3>\n<pre class=\"lang:js decode:true\" title=\"JavaScript\">$(function () {\r\n  $.each($(\"#tbl tbody\").children(), function () {\r\n    \/\/ hidden\u306e\u5024\u3092\u4e0a\u66f8\u304d\u3059\u308b\r\n    if ($(this).find(\"#chEnabled\").prop('checked')) {\r\n      $(this).find(\"input[name='itm.blEnabled']\").val('true');\r\n    }\r\n    else {\r\n      $(this).find(\"input[name='itm.blEnabled']\").prop('false');\r\n    }\r\n  });\r\n});<\/pre>\n<p>\u5bfe\u8c61\u30c1\u30a7\u30c3\u30af\u30dc\u30c3\u30af\u30b9\u306b\u30c1\u30a7\u30c3\u30af\u304c\u5165\u3063\u3066\u3044\u308b\u304b\u78ba\u8a8d\u3057\u3001hidden\u306e\u5024\u3092\u4e0a\u66f8\u304d\u3057\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<h3>\u30c1\u30a7\u30c3\u30af\u30dc\u30c3\u30af\u30b9OFF\/ON\u64cd\u4f5c\u6642<\/h3>\n<p>\u521d\u671f\u8868\u793a\u306e\u30b3\u30fc\u30c9\u306e\u4e0b\u306b\u4ee5\u4e0b\u3092\u8ffd\u52a0\u3002<\/p>\n<pre class=\"lang:js decode:true\" title=\"JavaScript\">  $(\"#tdChBox &gt; input\").change(function () {\r\n    if ($(this).prop('checked')) {\r\n      $(this).next(\"input[name='itm.blEnabled']\").val('true');\r\n    }\r\n    else {\r\n      $(this).next(\"input[name='itm.blEnabled']\").val('false');\r\n    }\r\n  });<\/pre>\n<p>&nbsp;<\/p>\n<h2>\u7d50\u679c<\/h2>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-421\" src=\"http:\/\/elink.tokyo\/wp-content\/uploads\/2017\/01\/chkboxfor2.png\" alt=\"\" width=\"177\" height=\"184\" \/><\/p>\n<p>\u3053\u3093\u306a\u3084\u308a\u304b\u305f\u3067\u3044\u3044\u306e\u304b\u5206\u304b\u308a\u307e\u305b\u3093\u304c\u3001\u7121\u4e8b\u306b\u53d6\u5f97\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>@Html.CheckBoxFor\u306e\u5024\u3092Request.Form.Get()\u3067\u53d6\u308a\u305f\u304b\u3063\u305f\u3093\u3067\u3059\u304c &lt;td&gt; @Html.CheckBoxFor(m =&gt; itm.blEnabled &#8230; <\/p>\n","protected":false},"author":1,"featured_media":1787,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[76],"tags":[],"class_list":["post-1823","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-asp-dotnet"],"_links":{"self":[{"href":"https:\/\/greentown.tokyo\/index.php?rest_route=\/wp\/v2\/posts\/1823"}],"collection":[{"href":"https:\/\/greentown.tokyo\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/greentown.tokyo\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/greentown.tokyo\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/greentown.tokyo\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1823"}],"version-history":[{"count":2,"href":"https:\/\/greentown.tokyo\/index.php?rest_route=\/wp\/v2\/posts\/1823\/revisions"}],"predecessor-version":[{"id":1859,"href":"https:\/\/greentown.tokyo\/index.php?rest_route=\/wp\/v2\/posts\/1823\/revisions\/1859"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/greentown.tokyo\/index.php?rest_route=\/wp\/v2\/media\/1787"}],"wp:attachment":[{"href":"https:\/\/greentown.tokyo\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/greentown.tokyo\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/greentown.tokyo\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}