Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ahmed Ilyas 7 posts 27 karma points
    Feb 11, 2014 @ 01:59
    Ahmed Ilyas
    0

    Issues with enctype for file upload

    I am having issues trying to return back an invalid model when a page is using the Html.BeginUmbracoForm() which renders the encType attribute in order for me to upload files from the client.

    My controller derives from SurfaceController.

    My controller has the following actions:

     public ActionResult UploadJobs()
            {
                var model = new UploadJobsModel();

                return PartialView(model);
            }

            [HttpPost]
            [ValidateAntiForgeryToken]
            public ActionResult UploadJobs(UploadJobsModelmodel)
            {
                if (!ModelState.IsValid)
                {
                    return PartialView(model);
                  
                }

                // TODO: Processing.
                return PartialView(model);
            }

     

    My view is like so:

     

    @model UmbracoSite.Models.Jobs.UploadJobsModel

    @using (Html.BeginUmbracoForm("UploadJobs", "Jobs"))
    {
        
        <div class="row">
                @Html.TextBoxFor(m => m.Files, new { type = "file", name = "Files" })
            </div>
            <div class="row">
                <input type="submit" value="Upload" id="cmdUploadJobs" />           
            </div>
    }

     

     

    The problem is, when you POST back and the validation fails, I want to return back that model with validation errors. This works except that the whole page breaks where the css/javascript references are no longer being referenced and only just the partial view seems to be rendered.

    However, on many other partial views I have done which do NOT use the BeginUmbracoForm and do not have a file upload control, it works fine.

    I need this particular view to work so I can upload files and display any validation errors back to the view should there be any.

     

    any thoughts? I am REALLY stuck.

     

  • Zakhar 171 posts 397 karma points
    Feb 11, 2014 @ 11:57
Please Sign in or register to post replies

Write your reply to:

Draft