Copied to clipboard

Flag this post as spam?

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


  • mikkel 143 posts 365 karma points
    Jul 05, 2020 @ 14:59
    mikkel
    0

    I got a problem making a image upload to members to edit

    Hi I want to make a image upload to my members where they can change their image themselves, but I simply can't find the solution to it. what im i doing wrong.

    My update model

    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Web;
    
    namespace Medlemmer.Models
    {
    
        public class UpdateMember
        {
            [Required]
            public string Name { get; set; }
    
            [Required]
            [EmailAddress]
            public string Email { get; set; }
            [Required]
            public string Password { get; set; }
    
            [Required]
            public string omMig { get; set; }
    
            [Required]
            public HttpPostedFileBase billede { get; set; }
        }
    }
    

    My update controller

    using Medlemmer.Models;
    using System.Web.Mvc;
    using Umbraco.Web.Mvc;
    
    namespace Medlemmer.Controllers
    {
        public class updateMemberController : SurfaceController
        {
            [HttpPost]
            [ActionName("MvcMemberUpdate")]
            public ActionResult MvcMemberUpdateForm(UpdateMember model)
            {
                var memberService = Services.MemberService;
                var member = memberService.GetByEmail(model.Email);
    
                member.SetValue("Navn", model.Name);
                member.SetValue("avatar", model.billede);
                member.SetValue("Om mig", model.omMig);
    
                memberService.Save(member);
    
                TempData["Success"] = true;
    
                return RedirectToCurrentUmbracoPage();
            }
        }
    }
    

    member profile page when they are logged in, it is here i want the to edit there image

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.Profil>
    @using ContentModels = Umbraco.Web.PublishedContentModels;
    @using Medlemmer.Controllers
    @using Medlemmer.Models
    @{
        Layout = "master.cshtml";
        var medlem = Members.GetCurrentMember();
        var test = Umbraco.MembershipHelper.GetCurrentMemberProfileModel();
    
        var virker = ApplicationContext.Current.Services.MemberService.GetMembersByMemberType("newsMember");
        var bruger = Umbraco.MembershipHelper.GetCurrentMember();
        var test1 = ApplicationContext.Current.Services.MemberService.GetAllMembers();
    }
    
    
    
    
    
    <div class="container">
        <div class="col-md-4">
            <img src="@bruger.GetPropertyValue("avatar")" class="img-thumbnail img-responsive" style="width: 100%;" />
            @Umbraco.Field("avatarupload")
    
        </div>
        <div class="col-md-8">
            <h1 class="page-header">Velkommen @bruger.Name</h1>
            <p class="text-muted">Email: @test.Email</p>
            <p class="text-muted">Lidt om mig: @bruger.GetPropertyValue("bio")</p>
            <p>@bruger.Id</p>
        </div>
    </div>
    
    
    <div class="container">
        <div class="col-md-8">
    
            @Html.Partial("Rediger profil")
    
        </div>
    </div>
    
    }
    
    
    
    
    @using (Html.BeginUmbracoForm<RegisterController>("Register"))
    {
        <!-- Sikkerhed og skal huskes -->
        @Html.AntiForgeryToken()
        @Html.ValidationSummary(true)
        <div class="container">
            <fieldset>
                <div class="label">
                </div>
                <br />
                <div class="">
                    <h6>Navn: </h6>
                    @Html.EditorFor(Model => Model.Name)
                    @Html.ValidationMessageFor(Model => Model.Name)
                </div>
                <br />
                <div class="">
                    <h6>Email: </h6>
                    @Html.EditorFor(model => model.Email)
                    @Html.ValidationMessageFor(model => model.Email)
                </div>
                <br />
    
                <div class="">
                    <h6>Adgangskode:</h6>
                    @Html.EditorFor(model => model.Password)
                    @Html.ValidationMessageFor(model => model.Password)
                </div>
                <br />
    
                <div class="">
                    <h6>Om mig:</h6>
                    @Html.TextAreaFor(model => model.omMig)
                    @Html.ValidationMessageFor(model => model.omMig)
                </div>
                <div>
                    @Html.TextBoxFor(m => m.billede, new { type = "file" })
                    @Html.ValidationMessageFor(model => model.billede)
                </div>
                <br />
                <button class="btn btn-default">Opret bruger</button>
            </fieldset>
        </div>
    
    
    }
    

    i have also make the Partial edit profile snippet that umbraco have and i i can add the image upload to that one it would be creat

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    
    @using System.Web.Mvc.Html
    @using ClientDependency.Core.Mvc
    @using Umbraco.Web
    @using Umbraco.Web.Controllers
    @using Medlemmer.Controllers
    @using Medlemmer.Models
    
    
    @{
        var profileModel = Members.GetCurrentMemberProfileModel();
    
        Html.EnableClientValidation();
        Html.EnableUnobtrusiveJavaScript();
        Html.RequiresJs("/umbraco_client/ui/jquery.js");
        Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.min.js");
        Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.unobtrusive.min.js");
    
        var success = TempData["ProfileUpdateSuccess"] != null;
    }
    
    @*NOTE: This RenderJsHere code should be put on your main template page where the rest of your script tags are placed*@
    @Html.RenderJsHere()
    
    @if (Members.IsLoggedIn() && profileModel != null)
    {   
        if (success)
        {
            @* This message will show if RedirectOnSucces is set to false (default) *@
            <p>Profilen blev opdateret</p>
        }
    
        using (Html.BeginUmbracoForm<UmbProfileController>("HandleUpdateProfile"))
        {
            <fieldset>
                <legend>Rediger din profil</legend>
    
                @Html.ValidationSummary("profileModel", true)
    
                @Html.LabelFor(m => profileModel.Name)
                @Html.TextBoxFor(m => profileModel.Name)
                @Html.ValidationMessageFor(m => profileModel.Name)
                <br />
    
                @Html.LabelFor(m => profileModel.Email)
                @Html.TextBoxFor(m => profileModel.Email)
                @Html.ValidationMessageFor(m => profileModel.Email)
                <br />
                @Html.TextBoxFor(m => profileModel.billede, new { type = "file" })
                @for (var i = 0; i < profileModel.MemberProperties.Count; i++)
                {@*
                @Html.LabelFor(m => profileModel.MemberProperties[i].Value, profileModel.MemberProperties[i].Name)
    
                    By default this will render a textbox but if you want to change the editor template for this property you can
                    easily change it. For example, if you wanted to render a custom editor for this field called "MyEditor" you would
                    create a file at ~/Views/Shared/EditorTemplates/MyEditor.cshtml", then you will change the next line of code to
                    render your specific editor template like:
                    @Html.EditorFor(m => profileModel.MemberProperties[i].Value, "MyEditor")
    
                @Html.EditorFor(m => profileModel.MemberProperties[i].Value)
                @Html.HiddenFor(m => profileModel.MemberProperties[i].Alias) *@
                <br />
            }
    
                <button>Gem</button>
            </fieldset>
        }       
    }
    
  • Paul Seal 419 posts 2284 karma points MVP 3x c-trib
    Jul 14, 2020 @ 22:31
    Paul Seal
    0

    Hi

    I had this same scenario and I managed to get it to work. I wrote a blog post to help people like you and me who are struggling with it.

    I hope it helps.

    https://codeshare.co.uk/blog/how-to-upload-a-file-to-umbraco-from-a-front-end-form/

    Kind regards

    Paul

  • mikkel 143 posts 365 karma points
    Jul 15, 2020 @ 09:52
    mikkel
    0

    Hi Poul

    I have started with your guide but i am not shure where I should make this file here, "IMediaUploadService Interface" is it a models or controller file or should it be a whole 3 place. I cant read it on your website :D

  • Paul Seal 419 posts 2284 karma points MVP 3x c-trib
    Jul 15, 2020 @ 09:54
    Paul Seal
    0

    If you are free now I have 10 mins, I could show you on Zoom.

    Follow me on twitter, I'll follow you back and then we can set up a quick call to share your screen and help you through it

    https://twitter.com/codesharepaul

Please Sign in or register to post replies

Write your reply to:

Draft