Hello everyone, i have a problem when i want to update member data.
On the platform, the member can register and access the personal area. Here you can edit the data and save it. The problem arises when from the form the data should go to the controller with the "ProfileModel", but this arrives without some information: id, UserName, guiid etc.. Why? Anyone have a suggestion? Many thanks in advance.
In .cshtml file
using (Html.BeginUmbracoForm<UmbProfileController>("HandleUpdateProfile", new { RedirectUrl = profileModel.RedirectUrl }))
{
....... form here
}
Here in the controller, "ProfileModel model" have much data empty or null.
// Build a profile model to edit
ProfileModel = await _memberModelBuilderFactory
.CreateProfileModel()
// If null or not set, this will redirect to the current page
.WithRedirectUrl(null)
// Include editable custom properties on the form
.WithCustomProperties(true)
.BuildForCurrentMemberAsync()
// Build a profile model to edit
var profileModel = await memberModelBuilderFactory
.CreateProfileModel()
// If null or not set, this will redirect to the current page
.WithRedirectUrl(null)
// Include editable custom properties on the form
.WithCustomProperties(true)
.BuildForCurrentMemberAsync();
@inherits Umbraco.Cms.Web.Common.Macros.PartialViewMacroPage
@using Umbraco.Cms.Core.Services
@using Umbraco.Cms.Web.Common.Security
@using Umbraco.Cms.Web.Website.Controllers
@using Umbraco.Cms.Web.Website.Models
@using Umbraco.Extensions
@inject MemberModelBuilderFactory memberModelBuilderFactory;
@inject IMemberExternalLoginProviders memberExternalLoginProviders
@inject IExternalLoginWithKeyService externalLoginWithKeyService
@{
// Build a profile model to edit
var profileModel = await memberModelBuilderFactory
.CreateProfileModel()
// If null or not set, this will redirect to the current page
.WithRedirectUrl(null)
// Include editable custom properties on the form
.WithCustomProperties(true)
.BuildForCurrentMemberAsync();
var success = TempData["FormSuccess"] != null;
}
I use "profileModel" to bind properties with input tag. If i used "@Model.Username" for the exemple, the Model is a current page.
Being new to Umbraco, I still need to understand its logic well... so I created a custom controller to check what happens... In my controller I removed the prefix :
Before
public async Task<IActionResult> HandleUpdateProfile([Bind(Prefix = "profileModel")] ProfileModel model)
After
public async Task<IActionResult> HandleUpdateProfile(ProfileModel model)
And now the "profileModel" that comes as a parameter is correctly set but without the changes!
I have discovered that this will cause an error because when disabled it fails to send the username in the post. Try setting readonly instead of disabled, does your post then work?
Those values will only get passed to the controller if they exist in your form post, so if you want to access them there then you need to add them as hidden fields in your form.
There is a loop on the member properties which are also bound to their input tags. So the values are changeable from the front-end but not pass to the controller
for (var i = 0; i < profileModel.MemberProperties.Count; i++)
{
@Html.LabelFor(x => profileModel.MemberProperties[i].Value, profileModel.MemberProperties[i].Name)
<input asp-for="@profileModel.MemberProperties[i].Value" class="form-control" />
}
At the end of everything, out of the table tag but into "using":
I haven't personally looked into the Umbraco source to see what the UmbProfileController does, but if I use that macro and update anything it all gets updated correctly when the form is posted, even custom properties.
Have you downloaded the Umraco source code in order to determine this?
In the .cshtml file where the member can edit their profile, a condition for excluding some properties, created the problem. Having moved this to the block at the top of the file:
@{
var list = profileModel.MemberProperties.Where(x => x.Alias.Equals("prop1") ||
x.Alias.Equals(("prop2"))
).ToList();
}
Can't update member's data
Hello everyone, i have a problem when i want to update member data.
On the platform, the member can register and access the personal area. Here you can edit the data and save it. The problem arises when from the form the data should go to the controller with the "ProfileModel", but this arrives without some information: id, UserName, guiid etc.. Why? Anyone have a suggestion? Many thanks in advance.
In .cshtml file
Here in the controller, "ProfileModel model" have much data empty or null.
we would need to see your form to ascertain what you are passing back, you should add id, UserName, guiid etc as hidden fields on your form
Into using there is a table with:
The input it's disable only for the front-end edit.
For the exemple this value, will arrive like empty.
So, you mean add all values and some all this like: guiid, username must be hidden?
How are you initializing your model?
Are you doing something like
Yes, in this way:
what usings/model import do you have in your view? could be you should be doing
I use "profileModel" to bind properties with input tag. If i used "@Model.Username" for the exemple, the Model is a current page.
That's fine, just wanted to make sure.
Are you using the built in controller and methods or have you created your own?
UmbProfileController provides it's own HandleUpdateProfile so you shouldn't need to create one
Being new to Umbraco, I still need to understand its logic well... so I created a custom controller to check what happens... In my controller I removed the prefix : Before
After
And now the "profileModel" that comes as a parameter is correctly set but without the changes!
If you use the OOB macro code without creating your own controller, does it save changes?
No, the profileModel doesn't arrive evaluated to the controller
What error(s) are you receiving? What exact version of Umbraco do you have installed?
I am currently using this OOB macro code in U10 and 11 without any issues
I have no errors, I created a macro with "Edit profile" snippet and the prfofileModel is not evaluated in the controller. I'm using Umbraco v11.
Odd, I would expect an error back from your post at least if it is failing.
I did notice this code you posted
I have discovered that this will cause an error because when disabled it fails to send the username in the post. Try setting readonly instead of disabled, does your post then work?
I've removed disabled and Username is ok. But all member's properties, key, creation date and others... have not a value.
Those values will only get passed to the controller if they exist in your form post, so if you want to access them there then you need to add them as hidden fields in your form.
There is a loop on the member properties which are also bound to their input tags. So the values are changeable from the front-end but not pass to the controller
At the end of everything, out of the table tag but into "using":
I haven't personally looked into the Umbraco source to see what the UmbProfileController does, but if I use that macro and update anything it all gets updated correctly when the form is posted, even custom properties.
Have you downloaded the Umraco source code in order to determine this?
In the .cshtml file where the member can edit their profile, a condition for excluding some properties, created the problem. Having moved this to the block at the top of the file:
the problem can be said to be solved.
Thanks
is working on a reply...