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 10, 2014 @ 12:45
    Ahmed Ilyas
    0

    POSTing file to controller action?

    I am inheriting a project which is somewhat built in Umbraco 6 and I am not familiar with Umbraco but learning thus far.

    A partial view is using an existing template which effectively has this in its template:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = "MvcBanner.cshtml";
    }

    @Umbraco.RenderMacro("Breadcrumb") 

    @Umbraco.Field("pageName")
    @Umbraco.Field("pageInstructions", insertBefore: "", insertAfter: "", convertLineBreaks: true)

    @Html.Action(@Umbraco.Field("MVCActionName").ToString(), @Umbraco.Field("MVControllerName").ToString()) 
     
    }

     

    This template is being used by a page "UploadJobs.cshtml"

    Now, on the UploadJobs.cshtml I have a few fields bound to a model and then a file upload:

    @model Models.JobsModel

     

    @using(Html.BeginUmbracoForm("UploadJobs", "Jobs")) {

    @Html.TextBoxFor(m => m.Name);

    @Html.TextBoxFor(m => m.Files, new { type = "file", name = "Files" })

    <input type="submit" value="Upload" id="cmdSubmitJobs" />

    }

     

    My action method looks like this (which derives from SurfaceController):

     

    [HttpPost]
    [ValidateAntiForgeryToken]
    public PartialViewResult UploadJobs(UploadJobs model)
    {

       if (!ModelSate.IsValid) { return PartialView(model); }

     

       // TODO Processing

       return PartialView(model);

    }

     

    When submitting, everything seems fine but when returning the model back to the view (i.e validation fails), it seems to break the page completely when rendering (i.e all styles and all formatting is gone) and any javascript//jquery functions I have returns errors when the document is being rendered

    I tried returning CurrentUmbracoPage but seem to have problems doing so as at runtime it throws an exception saying that it can only be used when the view itself is posting to a SurfaceController - but the controller is a surfacecontroller. Damned if I do and damned if I don't :)

    thoughts? I want to be able to obviously return the model if it is invalid

Please Sign in or register to post replies

Write your reply to:

Draft