0

2 つの質問があります。

1.) Fine Uploader をフォームに配置しましたが、コントローラーの入力フィールドに入力されたコンテンツが表示されないのはなぜでしょうか。どうすればそれを解決できますか?

2.) アップロード プロセスが起動する前にフィールドの検証を行うにはどうすればよいですか?

誰かが助けてくれることを願っています!

これが私のコードです:

モデル:

public class UploadFileModel
{
    [StringLength(100)]
    [Display(Name = "* Title:")]
    public string Title { get; set; }

    [StringLength(300)]
    [Display(Name = "Description:")]
    public string Description { get; set; }
}

意見:

@model mowee.Models.UploadFileModel

<link href="~/Scripts/fineuploader/fineuploader-3.5.0.css" rel="stylesheet" />

@using (Html.BeginForm("UploadFile", "Home", FormMethod.Post, new { id = "uploadForm", enctype = "multipart/form-data" }))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary()

    <fieldset>
        <legend>Video Upload</legend>
        <ol>
            <li>
                @Html.LabelFor(m => m.Title)
                @Html.TextBoxFor(m => m.Title, new { @Class = "action add", title = "Enter your video/movie title here." })
            </li>
            <li>
                @Html.LabelFor(m => m.Description)
                @Html.TextAreaFor(m => m.Description, new Dictionary<string, object> { { "rows", "3" } })
            </li>
        </ol>

        <div id="bootstrapped-fine-uploader"></div>
        <script src="~/Scripts/fineuploader/fineuploader-3.5.0.js"></script>
        <script>
            function createUploader() {
                var uploader = new qq.FineUploader({
                    element: document.getElementById('bootstrapped-fine-uploader'),

                    multiple: false,
                    validation: {
                        sizeLimit: 2147483648 //2GB
                    },
                    request: {
                        endpoint: '/Home/UploadFile'
                    },
                    text: {
                        uploadButton: '<div><i class="icon-upload icon-white"></i>* Upload Video</div>'
                    },
                    template: '<div class="qq-uploader span12">' +
                    '<pre class="qq-upload-drop-area span12"><span>{dragZoneText}</span></pre>' +
                    '<div id="btnUpload" class="qq-upload-button btn btn-success" style="width: 33%;">{uploadButtonText}</div>' +
                    '<span class="qq-drop-processing"><span>{dropProcessingText}</span><span class="qq-drop-processing-spinner"></span></span>' +
                    '<ul class="qq-upload-list" style="margin-top: 10px; text-align: center;"></ul>' +
                    '</div>',
                    classes: {
                        success: 'alert alert-success',
                        fail: 'alert alert-error',
                        dropActive: "cssClassToAddToDropZoneOnEnter"
                    }
                });
            }
            window.onload = createUploader;
        </script>
    </fieldset>
}

コントローラ:

[HttpPost]
[AllowAnonymous]
[AcceptVerbs(HttpVerbs.Post)]
public JsonResult UploadFile(string qqfile, UploadFileModel myModel)
{
    if (ModelState.IsValid)
    {
        try
        {
            HttpPostedFileBase uploadFile = null;
            uploadFile = Request.Files[0];

            if (uploadFile != null && uploadFile.ContentLength > 0)
            {
                if (myModel.Title != null || myModel.Description != null)
                {
                   **//but UploadFileModel is null. WHY??????? Anyone an idea what i did wrong???
                   //write data to DB**
                }
            }
            else
            {
                ModelState.AddModelError("", "Please choose a video/movie.");
                return Json(new { success = false, message = "Please choose a video/movie." }, "application/json");
            }
        }
        catch (Exception ex)
        {
            ModelState.AddModelError("", "An error occured. Try again.");
            mailUtils.SendBugMail(ex, this.HttpContext);
            return Json(new { success = false, message = "An error occured during upload. Try again." }, "application/json");
        }
        return Json(new { success = true, VideoLink = @ViewBag.VideoLink, VideoTranscoded = @ViewBag.Transcoded }, "application/json");//"text/html");
    }
    return Json(new { success = false, message = "An error occured during upload. Try again." }, "application/json");
}
4

2 に答える 2

0

質問への対処:

  1. Fine Uploader server-side examples repositoryにあるMVC4 の例を実際に見てください。この例に従ってサーバー側のコードをモデル化すれば、問題ないはずです。私は個人的に MVC4 開発者ではありませんが、リンクした例が機能することは知っています。
  2. onValidateおよびコールバックを使用onValidateBatchして、独自の検証タスクを実行できます。詳細については、コールバックのドキュメントをご覧ください。
于 2013-05-07T15:18:24.303 に答える