0
asp.net mvc 3에서 파일 업로드에 Valums 업 로더 플러그인을 사용했습니다. 다음은 양식 내에 양식 필드와 ajax 쿼리 업로드 버튼이있는보기입니다. 내가 제대로하고 있는지 확신 할 수 없다. 보기 필드에서 변경해야하는 내용이므로 양식 필드의 값을 업로드 할 파일을 선택하면 보낼 수도 있습니다.asp.net mvc에서 Valums 플러그인으로 Ajax 양식 제출 3
조회수 : I 데이터베이스에 데이터를 저장할 수 있도록 내가 HTTPOST 액션의 컨트롤러 형태의 값을 건네 수있는 방법
<link href="@Url.Content("~/Content/css/fileuploader.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Content/js/fileuploader.js")" type="text/javascript"></script>
@using (Html.BeginForm("Upload","AjaxUpload")) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Upload Image File</legend>
<div class="editor-label">
@Html.Label("Select Language")
</div>
<div>
@Html.DropDownList("Language1", (SelectList) ViewBag.lang)
</div>
<div class="editor-label">
@Html.Label("Select Category")
</div>
<div>
@Html.DropDownList("ParentCategoryID", ViewBag.ParentCategoryID as SelectList)
</div>
<div id="file-uploader">
<noscript>
<p>
Please enable JavaScript to use file uploader.</p>
</noscript>
</div>
</fieldset>
}
**<script type="text/javascript">
var uploader = new qq.FileUploader
({
element: document.getElementById('file-uploader'),
action: '@Url.Action("upload")', // put here a path to your page to handle uploading
allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'], // user this if you want to upload only pictures
sizeLimit: 4000000, // max size, about 4MB
minSizeLimit: 0 // min size
});
</script>**
. 여기에는 데이터베이스에 데이터를 저장하는 업로드 작업이 있지만 양식 게시로 전송되는 값을 검색하는 것은 알 수 없습니다.
액션
[HttpPost]
public ActionResult Upload(HttpPostedFileBase qqfile)
{
var wav = new PlayWav
{
Name = ***filename***,
CategoryID = ***value from category dropdown select list***,
UserID = repository.GetUserID(HttpContext.User.Identity.Name),
LanguageID = int.Parse(***value from language dropdown select list***),
UploadDateTime = DateTime.Now,
ActiveDateTime = DateTime.Now,
FilePath = "n/a"
};
if (qqfile != null)
{
// this works for IE
var filename = Path.Combine(Server.MapPath("~/App_Data/Uploads"), Path.GetFileName(qqfile.FileName));
qqfile.SaveAs(filename);
return Json(new { success = true }, "text/html");
}
else
{
// this works for Firefox, Chrome
var filename = Request["qqfile"];
if (!string.IsNullOrEmpty(filename))
{
filename = Path.Combine(Server.MapPath("~/App_Data/Uploads"), Path.GetFileName(filename));
using (var output = System.IO.File.Create(filename))
{
Request.InputStream.CopyTo(output);
}
**db.PlayWavs.Attach(wav);
db.SaveChanges();**
return Json(new { success = true });
}
}
return Json(new { success = false });
}
PLZ 어떻게 행동 매개 변수를 사용하여 컨트롤러 – CodeManiac
의 업로드 작업에 PARAMS 값을 얻을 수 말해 것 :'공공 ActionResult 업로드 (HttpPostedFileBase qqfile, 문자열 PARAM1, 문자열 PARAM2) '또는 보기 모델을 사용하면 더 효율적입니다. 'public ActionResult Upload (MyViewModel model)'속성 이름이 전송 한 매개 변수 이름과 일치합니다. –