フォームにアップロードされたファイルをチェックして、それが CSV または TXT ファイルであることを確認したいと考えています。
以下のように、カスタム属性を作成しました。
public class ValidateUploadAttribute : RequiredAttribute
{
    public override bool IsValid(object value)
    {
        var file = value as HttpPostedFileBase;
        if (file == null)
        {
            return false;
        }
        if (file.ContentType != "text\\CSV" || file.ContentType != "text\\TXT")
        {
            return false;
        }
        return true;
    }
}
そして、このようなビューモデルを作成しました
[ValidateUploadAttribute(ErrorMessage = "Please select a TXT or CSV file")]
public HttpPostedFileBase File { get; set; }
そして、私のHttpPostコントローラーは次のようになります
public ActionResult Upload(UploadViewModel uploadViewModel, string site)
{
    ...
}
したがって、この時点まではすべて問題ありません。ValidateUploadAttributeが呼び出されて成功または失敗し、ファイルの種類が正しくありません。問題は、このアップロード フォームが、 model is not of type の別のビューの内部にある部分的なビューになるUploadViewModelこと@Html.ValidateFor(x => x.File)です。検証ヘルパーをビューに入れません)
部分的なビュー
<div id="upload-form" class="div-center content-div" style="margin-top: 15px;">
@using (Html.BeginForm("Upload", "Association", FormMethod.Post, new { enctype = "multipart/form-data", id = "upload-form"}))
{
    <input type="file" name="File" style="width: 79%;"/>
    <input type="submit" value="Upload for Add" style="width: 19%;"/>
}