Hi every one.
I dont now if my member controller is made right. I want it to show text in textboxes so my members can update them by them self. But something is going wrong i cant in my razor code acces my proberties in my model.
i am not sure i am doing it right ?? it is my first time ever making a update method in razor and umbraco
Here is my controller
using Medlemmer.Models;
using System.Reflection.Metadata;
using System.Web.Mvc;
using Umbraco.Web.Mvc;
namespace Medlemmer.Controllers
{
public class updateMemberController : SurfaceController
{
// GET: Register
public ActionResult OpdaterMedlem(Models.UpdateMember model)
{
// Check if the user is logged in
if (!User.Identity.IsAuthenticated)
{
// Send the user to the login page
Redirect("/login");
}
// The model is not valid yet
if (!ModelState.IsValid)
{
// Display the current Umbraco page (do not redirect)
return CurrentUmbracoPage();
}
// Create new instance of "MemberService"
var memberService = Services.MemberService;
// Get the details of the user currently logged in
var profileModel = Members.GetCurrentMemberProfileModel();
// Get the custom properties for the member
var member = memberService.GetByEmail(profileModel.Email);
// Check if the email address is in the database
if (member == null)
{
ModelState.AddModelError("", "Er du sikker på det er den rigtige du opdatere!");
return CurrentUmbracoPage();
}
// Update the member properties
member.Properties["bio"].Value = model.omMig;
member.Properties["email"].Value = model.Email;
member.Properties["name"].Value = model.Name;
member.Properties["avatar"].Value = model.billede;
// Save in Umbraco
memberService.Save(member);
return Redirect("/");
}
}
}
Here is my razor view
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.Profil>
@using ContentModels = Umbraco.Web.PublishedContentModels;
@using Medlemmer.Controllers
@using Umbraco.Web.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();
}
@using (Html.BeginUmbracoForm<updateMemberController>("OpdaterMedlem", FormMethod.Get))
{
<div class="panel">
<div class="col-md-5">
@Html.TextBoxFor(m => m.Email)<!-- Here it goes wrong to i cant use .Email because it dont exixst -->>
</div>
</div>
}
Here is my 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; }
}
}
Controller:-
You have to pass UpdateMember class object in updateMemberController. So, that UpdateMember object can be accessed in the View.
Front-end:-
Form need to be moved to the partial as your current model is ContentModel. So, m.Email will not exists.
Example Below -
View:-
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.Profil>
@using ContentModels = Umbraco.Web.PublishedContentModels;
@using Medlemmer.Controllers
@using Umbraco.Web.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();
}
@Html.Partial("MemberUpdate",Model.Content.UpdateMember)
Partial MemberUpdate.csthml
As UpdateMember is the modal for this Partial View so you will get m.Email.
@inherits Umbraco.Web.Mvc.UmbracoViewPage<UpdateMember>
@using (Html.BeginUmbracoForm<updateMemberController>("OpdaterMedlem", FormMethod.Get))
{
<div class="panel">
<div class="col-md-5">
@Html.TextBoxFor(m => m.Email)<!-- Here it goes wrong to i cant use .Email because it dont exixst -->>
</div>
</div>
}
Please try and let me know if this works for you or have any further queries.
i cant get it to work. i can show the members information, bu i cant show it in af textbox. i dont now how to do that. i have try many things as getting acces to the controllers and models by using
Hi Shaishav Karnani
I practice CRUD. so it is only exercise. I want to share it with you, so I can learn something too. I'll share it with you when I get home from work tomorrow
update method/Controller doesent work!
Hi every one. I dont now if my member controller is made right. I want it to show text in textboxes so my members can update them by them self. But something is going wrong i cant in my razor code acces my proberties in my model. i am not sure i am doing it right ?? it is my first time ever making a update method in razor and umbraco
Here is my controller
Here is my razor view
Here is my model
Controller:- You have to pass UpdateMember class object in updateMemberController. So, that UpdateMember object can be accessed in the View.
Front-end:- Form need to be moved to the partial as your current model is ContentModel. So, m.Email will not exists.
Example Below -
View:-
Partial MemberUpdate.csthml
As UpdateMember is the modal for this Partial View so you will get m.Email.
Please try and let me know if this works for you or have any further queries.
Regards,
Shaishav
i cant get it to work. i can show the members information, bu i cant show it in af textbox. i dont now how to do that. i have try many things as getting acces to the controllers and models by using
and then i try to get the
To be the the textbox that have to have the text inside it
I want the information in the image to be in textbox so that it is ready to be edited by the member
Hi Mikkel,
Above solution should work. Do you want to share your solution and we can try for you?
As it’s difficult to troubleshoot why it’s not working for you.
Regards,
Shaishav
Hi Shaishav Karnani I practice CRUD. so it is only exercise. I want to share it with you, so I can learn something too. I'll share it with you when I get home from work tomorrow
Hi Shaishav
how can i share it with you ?? :D
is working on a reply...