0

I would like to use 2 models in a same view. I use 2 HtmlHelper and this work perfecly but I don't know how to bing data to my HtmlHelper.

In my view :

@{
    Models.Users.EmailChangeRequest EmailRequest = new Gotham.Models.Users.EmailChangeRequest();
    EmailRequest.Email = ViewBag.EmailAdress;

    var EmailHelper = new HtmlHelper<Gotham.Models.Users.EmailChangeRequest>(ViewContext, this);

    Models.Users.PasswordChangeRequest PasswordRequest = new Models.Users.PasswordChangeRequest();
    var PasswordHelper = new HtmlHelper<Gotham.Models.Users.PasswordChangeRequest>(ViewContext, this);
}

and

using (EmailHelper.BeginForm("UpdateEmail", "Users", FormMethod.Post))
{
    @EmailHelper.AntiForgeryToken()
    @EmailHelper.ValidationSummary(true, "", new { @class = "text-danger" }) 
    @EmailHelper.LabelFor(m => m.Email, "Votre adresse email");
    @EmailHelper.EditorFor(m => m.Email, new { placeholder = "marie.dupont@mail.fr" }) 
    @EmailHelper.ValidationMessageFor(m => m.Email, "", new { @class = "text-danger" })  
    <input type="submit" value="Modifier mon email"/>
}
using (PasswordHelper.BeginForm("UpdateEmail", "Users", FormMethod.Post))
{
    @PasswordHelper.AntiForgeryToken()
    @PasswordHelper.ValidationSummary(true, "", new { @class = "text-danger" }) 
    @PasswordHelper.LabelFor(m => m.Password, "Mot de passe") 
    @PasswordHelper.PasswordFor(m => m.Password) 
    @PasswordHelper.ValidationMessageFor(m => m.Password, "", new { @class = "text-danger" }) 
    @PasswordHelper.LabelFor(m => m.Confirmation, "Confirmation") 
    @PasswordHelper.PasswordFor(m => m.Confirmation) 
    @PasswordHelper.ValidationMessageFor(m => m.Confirmation, "", new { @class = "text-danger" }) 
    <input type="submit" value="Modifier mon mot de passe" />
}

I would like the @EmailHelper.EditorFor to display the initial value of the email address.

The EmailHelper is created from the Models.Users.EmailChangeRequest type but I don't know how to communicate the "EmailRequest" instance containing the information to it.

Normally, we use the @Model directive, which loads the type AND data into the default HtmlHelper of the page (then we call @Htm.AnyFor(x => x.prop)). But there I have two different models. I just miss knowing how to transmit the data. I tried to put an "Email" value in ViewData, but no results.

Thanks for your help.

Mayzz
  • 116
  • 1
  • 9

0 Answers0