asp.netMVCの学習を始めたばかりです。写真を追加するにはどうすればよいですか?
MyPersonモデルには次のものがあります。
public class Person
{
public int ID { get; set; }
public string FirstName{ get; set; }
public string LastName{ get; set; }
public int Age { get; set; }
}
OK、MVCでデフォルトのWebアプリケーションを使用している場合、これはそれを行う1つの方法です。
モデルに画像URLのプロパティを追加します
public class Person
{
public int ID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
public string Image { get; set; }
}
それを保存し、[モデル]> [アイデンティティモデル]でモデルのDbSetを追加します
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
//ADD JUST THIS LINE
public DbSet<Person> People { get; set; }
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
ソリューションを再構築し、コントローラーも厚く追加します。ビューなどを生成します(スクリプトライブラリの参照、レイアウトページの使用)
次に、コントローラーのインデックスビューでこの行を見つけます
<td>
DisplayFor(modelItem => item.Image)
</td>
これで変更します
<td>
<img src="@Url.Content(item.Image)" />
</td>
次に、新しい人を作成するときに、画像入力に必要な画像URLを投稿するだけです。
たとえば、このURL http://mywindowshub.com/wp-content/uploads/2013/01/user-account.jpg
and on index it will look like this:
you just resize the image for your needs and you`re done. So i hope this helps you.
EDIT:
If you want to add your images from local folder, say you have a folder name images in Content, when you go to create new person in your image input text, you enter the image url like this: ~/Content/images/ImageName.jpg
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加