こんにちは。
Windows7, VisualStudio2015, ASP .NET MVC5を使って開発しています。
ASP .NET MVCを使うのは初めてです。
imageを登録する処理を書いています。
Controllers\Contents.csに次のようなmethodがあり、ここでbootstrap - fileinputを使ってuploadするように、とのことで、困っています。
[HttpPost]
public ActionResult Register(ContentsViewModel model) {
// 画像をアップロードしてテンポラリに保存する。
// 画像アップロード用のUIにはbootstrap - fileinputを使用する。
// 画像のlocalpathはmodel.Imageにstringで入っている。
// C:\tmp\tmp.jpgのように。
return this.RedirectToAction("Index", typeof(ContentsConfirmationController), model);
}
そもそもbootstrap - fileinputはどこにあるのか?
どうpathを渡せばよいか?
Webを見たのですが、layoutの方法などしか見つけられませんでした。
参考サイトなどをご示唆いただければ助かります。
ruby rails
ちなみに、Rubyの例を見つけました。
http://www.c-and-d.org/ruby/rails/rails_tips/2015/04/03/controller_file_upload/
upload_file = params['upload_file']
filename = upload_file.original_filename
dir = "#{Rails.root}files/"
FileUtils.mkdir(dir) unless File.directory?(dir)
filepath = File.join(dir, filename)
f = File.open(filepath, "wb")
f.write(upload_file.read)
f.close
C#なら、
string uploadfile = model.Image;
string filename = Path.GetFileName(uploadfile);
string savefolder = "server/files";
if (!Directory.Exists(savefolder)) Directory.CreateDirectory(savefolder);
upload処理
とかになるのでしょうか。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。