デバッグ実行時にIPアドレスを指定してアクセスする

WebMatrix (IIS Express)で公開サーバー - クリエイティブWeb
https://creativeweb.jp/personal-site/webmatrix

IIS Express で localhost 以外からアクセスする方法 - アーキテクチャをスマートに。
http://architect-wat.hatenablog.jp/entry/20130513/1368425906


Visual StudioでWebプロジェクトを開発しWebサーバーにIIS Expressを使用している場合、実行した時のURLはhttp://localhost:12345のようになります。

これをIPアドレスを指定してアクセスできるようにする方法です。
(ポートやIPは例)

1)Visual Studioで一回はWebアプリを実行しておく。

2)C:\Users\ユーザ名\Documents\IISExpress\config\applicationhost.configから該当項目を探してIPアドレス(やホスト名)に書き換えたものを追加する。




3)管理者権限なしで実行できるようにする。
コマンドプロンプトを管理者で実行して下記のコマンドを実行する。

netsh http add urlacl url=http://10.30.2.123:12345/ user=everyone

削除は下記コマンド

netsh http delete urlacl url=http://10.30.2.123:12345/



http://10.30.2.123:12345/にアクセスして、503等が返ってきたらタスクトレイのIIS Expressアイコンを右クリックして終了して、再度起動する。

ファイアウォールの説明は省略。

MVC5 EditorForの便利な使い方(ICollectionをバインド)

モデル: Models\Hoge.cs

public class Hoge {
    public virtual ICollection<Fuga> FugaCollection { get; set; }
}

モデル: Models\Fuga.cs

public class Fuga {
    public string FugaFuga { get; set; }
}

コントローラー: Controllers\HogeController.cs

[HttpPost]
public ActionResult Create(Hoge hoge) {
    // Do something
}

ビュー(テンプレート): Views\Hoge\EditorTemplates\Fuga.cshtml
(共通の場合はShared配下でよい)

@model Sample.Models.Fuga
@Html.TextBoxFor(model => model.FugaFuga) @* ただの例 任意の内容を記述する *@

ビュー(メイン): Views\Hoge\Create.cshtml

@model Sample.Models.Hoge

@* その1 ICollection<T>を渡す(テンプレート側のモデルの型はコレクションではない) *@
@Html.EditorFor(model => model.FugaCollection)

@* その2 テンプレート名を指定したい場合はプレフィックスを指定する *@
@{int idx = 0}
foreach (var item in Model.FugaCollection) {
    @Html.EditorFor(model => item, "Fuga", "FugaCollection[" + idx++ + "]")
}

テンプレート部分の内容をajax等で動的に追加削除する場合等はさらにBeginCollectionItemを組み合わせる。

MVC Series Part 1: Dynamically Adding Items Part 1 | //InterKnowlogy/ Blogs
http://blogs.interknowlogy.com/2014/08/01/mvc-series-part-1-dynamically-adding-items-part-1/

GitHub - danludwig/BeginCollectionItem: This Html Helper leverages the default model binder in ASP.NET MVC 2 and higher to materialize viewmodel collection properties from an HTTP POST.
https://github.com/danludwig/BeginCollectionItem

MVC5 jQuery hiddenフィールドを検証に使う

ignoreの既定値が":hidden"なので適当なセレクタを設定する。

例)

 @section Scripts { 
     @Scripts.Render("~/bundles/jqueryval") 
     <script type="text/javascript"> 
         $.validator.setDefaults({ 
             ignore: "" 
         }); 
     </script> 
 } 

.validate() | jQuery Validation Plugin
https://jqueryvalidation.org/validate/

MVC5 jQuery 動的項目の検証を有効にする

var form = $(formSelector)
            .removeData("validator") /* added by the raw jquery.validate plugin */
            .removeData("unobtrusiveValidation");  /* added by the jquery unobtrusive plugin */
$.validator.unobtrusive.parse(form);

こーゆーの見かけるが役に立たない(ajaxCompleteのタイミングもparseメソッドも)。
古いバージョンでは有効なのだろうか?

$(function () {
    //parsing the unobtrusive attributes when we get content via ajax
    $(document).ajaxComplete(function () {
        $.validator.unobtrusive.parse(document);
    });
});

asp.net mvc 4 - unobtrusive validation not working with dynamic content - Stack Overflow
http://stackoverflow.com/questions/14902581/unobtrusive-validation-not-working-with-dynamic-content

Applying unobtrusive jquery validation to dynamic content in ASP.Net MVC | XHalent Coding…
https://xhalent.wordpress.com/2011/01/24/applying-unobtrusive-validation-to-dynamic-content/

Enumを数値に変換して文字列に変換する

c# - How to convert from System.Enum to base integer? - Stack Overflow
http://stackoverflow.com/questions/908543/how-to-convert-from-system-enum-to-base-integer

Imports System.Runtime.CompilerServices

''' <summary>
''' Enum関連の処理を提供します。
''' </summary>
Public Module EnumExtension

    ''' <summary>
    ''' 指定した列挙体を基になる型に変換して、そのオブジェクトを表す文字列を返します。
    ''' </summary>
    ''' <param name="currentEnum">変換する対象のオブジェクト</param>
    ''' <returns>変換対象のオブジェクトを表す文字列</returns>
    <Extension()>
    Public Function ToNumString(currentEnum As [Enum]) As String
        Return Convert.ChangeType(
            currentEnum, [Enum].GetUnderlyingType(currentEnum.GetType())).ToString()
    End Function

End Module

TextのないCheckBoxにフォーカスの枠を表示する(WinForms)

Winforms Checkbox Focus Problem if no Text is Applied on Checkbox - Stack Overflow
http://stackoverflow.com/questions/2019675/winforms-checkbox-focus-problem-if-no-text-is-applied-on-checkbox

AutoSize : False
CheckAlign : MiddleCenter
Font: Courier New, 12.25pt
TextAlign: MiddleRight
Padding : 0, 5, 0, 0
Size : 26, 26
Text : " " (two spaces)

上手いことテキスト部分をチェックの部分に重ねるだけ。Font、Padding、Size、Textはお好みで。
試した感じではフォント依存。