Copied to clipboard

Flag this post as spam?

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


  • Silvija 58 posts 172 karma points
    Nov 01, 2019 @ 22:40
    Silvija
    0

    There is no current PublishedRequest

    Hello guys I am geting error if user do some wierd things in his frontend dashboard.

    I have 2 fields for image upload.

    Lets say that first image is allredy uploaded and he try to upload second image, but upload fails and display some warrning that image is too big, after that user decide to delete first image. When he click delete the first image he gets this error:

    enter image description here

    After that if user goes back and refresh the page, everthing will be ok.

    Anybody have an idea what is wrong?

  • Mario Lopez 168 posts 958 karma points MVP 4x c-trib
    Nov 02, 2019 @ 04:07
    Mario Lopez
    0

    Can we see the code you are using to delete that image? Frontend and backend.

  • Silvija 58 posts 172 karma points
    Nov 02, 2019 @ 16:04
    Silvija
    0

    Hi Mario,

    Yes ofcourse, here is the frontend code:

    <div class="form-row mb-0">
                <div class="form-group col-sm-3">
                    <p>@Umbraco.GetDictionaryValue("Main photo")</p>
                    <img class="mx-auto d-block img-fluid mb-2 height_250 preview" src="@(Model.LongSummaryImgPath == null ? "/Images/placeholder.jpg" : Model.LongSummaryImgPath.Url) " alt="your image" />
                    <small class="text-info">@Umbraco.GetDictionaryValue("Only jpg and png format")</small>
                    @if (Model.LongSummaryImgPath == null)
                    {
                        using (Html.BeginUmbracoForm("HandleUploadMedia", "MemberMedia", new { propertyName = "longSummaryImg" }, FormMethod.Post))
                        {
                            @Html.AntiForgeryToken()
                            @Html.TextBoxFor(Model => Model.File, htmlAttributes: new { id = "longSummaryImg", type = "file", onchange = "this.form.submit();", @class = "custom -file-input d-none" })
                            <input class="mt-2 btn btn-sm btn-block btn-success rounded-0 shadow_bme2" type="button" value="@Umbraco.GetDictionaryValue("Browse")" onclick="document.getElementById('longSummaryImg').click();" />
                            @Html.ValidationMessage("longSummaryImg", string.Empty, new { @class = "text-center text-white bg-danger d-block" })
                        }
                    }
                    else
                    {
                        using (Html.BeginForm("DeleteFile", "DeleteActions", new { fileId = Model.LongSummaryImgPath.Id, returnUrl = HttpContext.Current.Request.Url.PathAndQuery }, FormMethod.Post))
                        {
                            @Html.AntiForgeryToken()
                            @Html.HttpMethodOverride(HttpVerbs.Delete)
                            <button class="mt-2 btn btn-sm btn-block btn-danger rounded-0 shadow_bme2" type="submit" onclick="return confirm('@Umbraco.GetDictionaryValue("Are you sure you want to delete this image")');">
                                <i class="fa fa-trash"></i> @Umbraco.GetDictionaryValue("Delete")
                            </button>
                        }
                    }
                    @using (Html.BeginUmbracoForm("HandleSaveFileImgSource", "MemberMedia", new { propertyName = "longSummaryImgSource" }, FormMethod.Post))
                    {
                        @Html.AntiForgeryToken()
                        <div class="input-group mt-3">
                            <div class="input-group-prepend">
                                <label class="input-group-text rounded-0" for="inputGroupSelect01">@Umbraco.GetDictionaryValue("Image Source"):</label>
                            </div>
                            @Html.TextBoxFor(Model => Model.LongSummaryImgSource, htmlAttributes: new { @class = "form-control" })
                            <div class="input-group-append">
                                <button class="btn btn-success rounded-0" type="submit">@Umbraco.GetDictionaryValue("Save")</button>
                            </div>
                        </div>
                    }
                </div>
            </div>
    

    This is backend code for deleting images:

    [Authorize]
    [HttpDelete]
    [ValidateAntiForgeryToken]
    public ActionResult DeleteFile(int fileId, string returnUrl)
    {
        var item = Services.MediaService.GetById(fileId);
        Services.MediaService.Delete(item);
        if (!string.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl))
        {
            return Redirect(returnUrl);
        }
        else
        {
            return new HttpNotFoundResult();
        }
    
    }
    
  • Mario Lopez 168 posts 958 karma points MVP 4x c-trib
    Nov 02, 2019 @ 19:52
    Mario Lopez
    100

    It looks like you're using a normal MVC controller and your returned action results are for MVC as well.

    When you submit forms and return from the controller you have 'to stay' in the Umbraco workflow.

    In your view you have to use 'BeginUmbracoForm' instead 'BeginForm'.

    Your controller has to inherit from 'SurfaceController' and the way you return to umbraco pages is using some special Umbraco action results like 'return RedirectToUmbracoPage(id)' instead Redirect.

    If you want to keep your ModelState, i.e. errors in the form you need to use 'return CurrentUmbracoPage()'

  • Silvija 58 posts 172 karma points
    Nov 04, 2019 @ 13:30
    Silvija
    0

    Hi Mario,

    I changed it and its working now. I didnt know how flow is working, now I understund it better.

    Thanks

    BR

    Silvija

Please Sign in or register to post replies

Write your reply to:

Draft