こんにちは皆、私はasp.net mvcを使用してアプリケーションを作成しようとしています。これは、ユーザーが画像をアップロードしてダウンロードできるようにする最初のデータベースですデータベースとディスプレイに表示されますが、私はコントローラに問題があり、PDFファイルをダウンロードさせる方法を理解しています。asp.net codefirstを使用してpdfをダウンロードする
は、現在コントローラにPoliciesImageModelはどこ の定義が含まれていないと言って下線が引かれているこれらの問題
があります。そして、ポリシーはPoliciesImageModelが
ビューを認識されていない私はMattsの答えが、PoliciesImagesとファイルを使用していますこの問題
アップデートでanyhelpため
感謝をバイトに変換することができないと言って下線が引かれています
@model List<MyProject.Models.PoliciesPostVM>
@foreach (var item in Model)
{
@Html.DisplayFor(modelItem => item.FileName)
@Html.ActionLink("Download", "PoliciesDownload", new { id = item.ID})
}
コントローラ
public FileContentResult PoliciesDownload(int ID)
{
if (ID == 0) { return null; }
PoliciesImageModel policies = new PoliciesImageModel();
policies = policies.Where(a => a.ID == ID).SingleOrDefault();
return File(policies, "application/pdf");
}
モデル
public partial class PoliciesPostModel
{
public PoliciesPostModel()
{
Pdfs = new List<PoliciesImageModel>();
}
[Key]
[HiddenInput(DisplayValue = false)]
public int ID { get; set; }
[Required(ErrorMessage = "Heading is Required")]
[Display(Name = "File Name")]
public string FileName { get; set; }
public virtual ICollection<PoliciesImageModel> Pdfs { get; set; }
public IEnumerable<HttpPostedFileBase> File { get; set; }
}
public class PoliciesImageModel
{
[Key]
public int ID { get; set; }
public string Path { get; set; }
public virtual PoliciesPostModel Post { get; set; }
public string DisplayName { get; set; }
}
public class PoliciesImageVM
{
public int? ID { get; set; }
public string Path { get; set; }
public string DisplayName { get; set; }
public bool IsDeleted { get; set; }
}
public partial class PoliciesPostVM
{
public PoliciesPostVM()
{
Pdfs = new List<PoliciesImageVM>();
}
public int? ID { get; set; }
public string FileName { get; set; }
public IEnumerable<HttpPostedFileBase> Files { get; set; }
public List<PoliciesImageVM> Pdfs { get; set; }
public IEnumerable<PoliciesPostModel> Posts { get; set; }
}
DbConext
public class EFDbContext: DbContext
{
#region Policies
public DbSet<PoliciesPostModel> PoliciesPosts { get; set; }
public DbSet<PoliciesImageModel> PoliciesImages { get; set; }
#endregion Policies
//other Dbsets are here too....
}
'WHERE'は、LINQの拡張機能です。これを拡張メソッドとして使用するには、 'using'ステートメントで参照される適切な名前空間が必要です。ファイルの先頭に 'using System.Linq'を追加してください。そしてコレクションオブジェクトに対してのみ 'Where'を使うことができます。 – mason
あなたのポリシーは、ViewModel "PoliciesImageModel"のインスタンスです。あなたはそれからlinqクエリを実行することはできません。見えませんか? – Wheels73