Thank you for responding, however I did it like this if anyone needs it later on:
(only partly what I have but for the purpose it should give meaning)
MembersModel.cs
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Web.Security;
using System.Linq;
using System.Web;
namespace Models {
public class ChangePasswordModel
{
[Required]
[DataType(DataType.Password)]
[Display(Name = "Nuværende kode")]
public string OldPassword { get; set; }
[Required]
[StringLength(100, ErrorMessage = "{0} skal være minimum {2} karakterer langt.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Ny kode")]
public string NewPassword { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Bekræft ny kode")]
[Compare("NewPassword", ErrorMessage = "Ny kode og Bekræft ny kode er ikke ens.")]
public string ConfirmPassword { get; set; }
}
}
MembersController.cs
using Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Profile;
using System.Web.Security;
using umbraco;
using umbraco.cms.businesslogic.member;
using Umbraco.Web.Mvc;
namespace Controllers
{
public class MembersController : SurfaceController
{
[Authorize]
public ActionResult ChangePassword()
{
return CurrentUmbracoPage();
}
[Authorize]
[HttpPost]
public ActionResult ChangePassword(ChangePasswordModel model)
{
bool changePasswordSucceeded = false;
TempData["Success"] = changePasswordSucceeded;
if (ModelState.IsValid)
{
MembershipUser u = Membership.GetUser(User.Identity.Name, true /* userIsOnline */);
try
{
changePasswordSucceeded = u.ChangePassword(model.OldPassword, model.NewPassword);
}
catch { }
if (changePasswordSucceeded)
{
TempData["Success"] = true;
return RedirectToCurrentUmbracoPage();
}
else
{
ModelState.AddModelError("", library.GetDictionaryItem("ChangePasswordInvalidPassword"));
return CurrentUmbracoPage();
}
}
// If we got this far, something failed, redisplay form
return RedirectToCurrentUmbracoPage();
}
}
}
Partial View Macro Files
ChangePassword.cshtml (I have allowed the macro to be included in a richtext editor, you could also include it in a view, keep reading)
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@Html.Partial("~/Views/Partials/ChangePassword.cshtml", new Models.ChangePasswordModel {})
<!DOCTYPE html>
<head>
</head>
<body>
@*In the content field which in my case is a RTE you just add the macro*@
@Umbraco.Field("content")
@*However if you want to do this manually just do like this*@
@Html.Partial("ChangePassword", new Models.ChangePasswordModel { })
<script src="@Url.Content("~/Scripts/d/jquery-1.10.2.min.js")"></script>
<script src="@Url.Content("~/Scripts/d/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/d/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
</body>
</html>
Creating form based on model in Partial Macro View
Hi all,
I am trying to figure out how to create a form based on a custom model in a Partial Macro View but I cannot seem to get it to work.
It is just throwing an error that it cannot render the macro.
Something like this: Error loading Partial View script
I have seen a few having this kind of issue, however no solution.
Are there anyone who have solved this yet?
Regards,
Scott
I actually found a solution to this
Create a partial view and call that from the partial macro view using the model and writing out the form
Hi,
What you need to do is call the partial view in the view. In the partial view at the top do
@model your model name here
// rest of partial view
make call to your surface controller using either
@Html.BeginForm('actionname', controllername)
@Ajax.BeginForm('actionname', controllername)
:) Hope this helps
Hi Charles,
Thank you for responding, however I did it like this if anyone needs it later on:
(only partly what I have but for the purpose it should give meaning)
MembersModel.cs
MembersController.cs
Partial View Macro Files ChangePassword.cshtml (I have allowed the macro to be included in a richtext editor, you could also include it in a view, keep reading)
Partial View ChangePassword.cshtml
View (Template) Page.cshtml
Hopefully this helps someone in need!
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.