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
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>
}
}
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
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
My update controller
member profile page when they are logged in, it is here i want the to edit there image
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
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
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
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
is working on a reply...