Select Umbraco 7.2.6 的注册表中已有一个 MemberType
Select a MemberType already in the Registration Form in Umbraco 7.2.6
我正在寻找一种解决方案,可以通过选择 MemberType 在 umbraco 中获取注册表单。
我已经找到了有关获取已注册成员的成员类型的问题,或有关以编程方式创建成员类型的问题,但没有找到诸如注册表之类的问题,您可以在其中选择未来的成员类型。
此外,我发现了一些关于 cmsPropertyData
的信息,其中存储了会员详细信息。但是,难道没有比手动 SQL 查询或创建自己的 RegistrationModel 更简单的解决方案吗?
我已经有了标准注册表:
var registerModel = Members.CreateRegistrationModel();
using (Html.BeginUmbracoForm<UmbRegisterController>("HandleRegisterMember"))
{
<fieldset>
<legend>Registrierung</legend>
@Html.ValidationSummary("registerModel", true)
<div class="form-group">
@Html.LabelFor(m => registerModel.Name)
@Html.TextBoxFor(m => registerModel.Name, new { @class = "form-control" })
@Html.ValidationMessageFor(m => registerModel.Name)
</div>
<div class="form-group">
@Html.LabelFor(m => registerModel.Email)
@Html.TextBoxFor(m => registerModel.Email, new { @class = "form-control" })
@Html.ValidationMessageFor(m => registerModel.Email)
</div>
<div class="form-group">
@Html.LabelFor(m => registerModel.Password)
@Html.PasswordFor(m => registerModel.Password, new { @class = "form-control" })
@Html.ValidationMessageFor(m => registerModel.Password)
</div>
<div class="form-group">
</div>
@if (registerModel.MemberProperties != null)
{
for (var i = 0; i < registerModel.MemberProperties.Count; i++)
{
@Html.LabelFor(m => registerModel.MemberProperties[i].Value, registerModel.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 => registerModel.MemberProperties[i].Value)
@Html.HiddenFor(m => registerModel.MemberProperties[i].Alias)
<br/>
}
}
@Html.HiddenFor(m => registerModel.MemberTypeAlias)
@Html.HiddenFor(m => registerModel.RedirectUrl)
@Html.HiddenFor(m => registerModel.UsernameIsEmail)
<button class="btn btn-default">Registrieren</button>
</fieldset>
}
也许 MembershipHelper 有一些变化?
我更喜欢使用 umbraco 集成会员方法,但如果没有任何方法可以做到这一点,我认为不会有其他选择。
编辑:
我改变了这样做的方式如下:
首先,我得到所有
的 MemberType
var service = ApplicationContext.Services.MemberTypeService;
var memberTypes = service.GetAll();
然后我使用 memberTypes
执行一个 foreach 循环并将值赋给一个操作方法:
@foreach (var memberType in memberTypes)
{
<li>
@Html.ActionLink("Als " + memberType.Alias, "RedirectToCorrectRegistrationForm", "RegistrationSurface", new { memberTypeAlias = memberType.Alias }, new { @class = "page-scroll" })
</li>
}
SurfaceController 将 memberType 保存在 TempData 中,注册表单可以使用 memberTypeAlias 处理
public ActionResult RedirectToCorrectRegistrationForm(string memberTypeAlias)
{
TempData["MemberType"] = memberTypeAlias;
return RedirectToUmbracoPage(1072);
}
Register.cshtml:
var registerModel = Members.CreateRegistrationModel(TempData["MemberType"].ToString());
如果您只想获取您站点中当前存在的所有 MemberType,您可以使用 MemberTypeService,如下所示。
var service = ApplicationContext.Services.MemberTypeService;
var memberTypes = service.GetAll();
您甚至可以将整数数组传递给 GetAll()
以通过其 ID 获取特定类型。您可以通过访问单个成员类型的 .PropertyTypes
来迭代其所有属性。
我正在寻找一种解决方案,可以通过选择 MemberType 在 umbraco 中获取注册表单。 我已经找到了有关获取已注册成员的成员类型的问题,或有关以编程方式创建成员类型的问题,但没有找到诸如注册表之类的问题,您可以在其中选择未来的成员类型。
此外,我发现了一些关于 cmsPropertyData
的信息,其中存储了会员详细信息。但是,难道没有比手动 SQL 查询或创建自己的 RegistrationModel 更简单的解决方案吗?
我已经有了标准注册表:
var registerModel = Members.CreateRegistrationModel();
using (Html.BeginUmbracoForm<UmbRegisterController>("HandleRegisterMember"))
{
<fieldset>
<legend>Registrierung</legend>
@Html.ValidationSummary("registerModel", true)
<div class="form-group">
@Html.LabelFor(m => registerModel.Name)
@Html.TextBoxFor(m => registerModel.Name, new { @class = "form-control" })
@Html.ValidationMessageFor(m => registerModel.Name)
</div>
<div class="form-group">
@Html.LabelFor(m => registerModel.Email)
@Html.TextBoxFor(m => registerModel.Email, new { @class = "form-control" })
@Html.ValidationMessageFor(m => registerModel.Email)
</div>
<div class="form-group">
@Html.LabelFor(m => registerModel.Password)
@Html.PasswordFor(m => registerModel.Password, new { @class = "form-control" })
@Html.ValidationMessageFor(m => registerModel.Password)
</div>
<div class="form-group">
</div>
@if (registerModel.MemberProperties != null)
{
for (var i = 0; i < registerModel.MemberProperties.Count; i++)
{
@Html.LabelFor(m => registerModel.MemberProperties[i].Value, registerModel.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 => registerModel.MemberProperties[i].Value)
@Html.HiddenFor(m => registerModel.MemberProperties[i].Alias)
<br/>
}
}
@Html.HiddenFor(m => registerModel.MemberTypeAlias)
@Html.HiddenFor(m => registerModel.RedirectUrl)
@Html.HiddenFor(m => registerModel.UsernameIsEmail)
<button class="btn btn-default">Registrieren</button>
</fieldset>
}
也许 MembershipHelper 有一些变化?
我更喜欢使用 umbraco 集成会员方法,但如果没有任何方法可以做到这一点,我认为不会有其他选择。
编辑:
我改变了这样做的方式如下:
首先,我得到所有
的 MemberTypevar service = ApplicationContext.Services.MemberTypeService;
var memberTypes = service.GetAll();
然后我使用 memberTypes
执行一个 foreach 循环并将值赋给一个操作方法:
@foreach (var memberType in memberTypes)
{
<li>
@Html.ActionLink("Als " + memberType.Alias, "RedirectToCorrectRegistrationForm", "RegistrationSurface", new { memberTypeAlias = memberType.Alias }, new { @class = "page-scroll" })
</li>
}
SurfaceController 将 memberType 保存在 TempData 中,注册表单可以使用 memberTypeAlias 处理
public ActionResult RedirectToCorrectRegistrationForm(string memberTypeAlias)
{
TempData["MemberType"] = memberTypeAlias;
return RedirectToUmbracoPage(1072);
}
Register.cshtml:
var registerModel = Members.CreateRegistrationModel(TempData["MemberType"].ToString());
如果您只想获取您站点中当前存在的所有 MemberType,您可以使用 MemberTypeService,如下所示。
var service = ApplicationContext.Services.MemberTypeService;
var memberTypes = service.GetAll();
您甚至可以将整数数组传递给 GetAll()
以通过其 ID 获取特定类型。您可以通过访问单个成员类型的 .PropertyTypes
来迭代其所有属性。