我的MVC 5项目正在使用Facebook登录。 Inside ExternalLoginCallback(string returnUrl)
AccountController.cs我解析Facebook回应以获取姓名,生日和电子邮件,然后将这些值推入修改后的ExternalLoginConfirmationViewModel
。这工作正常,Model
在ExternalLoginConfirmation.cshtml包含值,使它显示正确。如何将ExternalLoginConfirmation Model值传递给提交的模型
我ExternalLoginConfirmation.cshtml:
@model itssamsbirthday.Models.ExternalLoginConfirmationViewModel
@{
ViewBag.Title = "Finalize Account";
}
<h2>Hello @Model.FirstName!</h2>
<h3>You've successfully authenticated with <strong>@ViewBag.LoginProvider</strong>.</h3>
@using (Html.BeginForm("ExternalLoginConfirmation", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
<h4>Finalize your account below.</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<p class="text-info">
Your profile:
<div><strong>First Name</strong>: @Model.FirstName</div>
<div><strong>Last Name</strong>: @Model.LastName</div>
<div><strong>Email</strong>: @Model.Email</div>
<div><strong>Birthday</strong>: @String.Format("{0:M/d/yyyy}", Model.BirthDate)</div>
</p>
<div class="text-info">
Select the <strong>Birthday Cake</strong> that best represents you:
</div>
<div class="form-group">
@Html.LabelFor(m => m.ProfileCake, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(m => m.ProfileCake, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(m => m.ProfileCake, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-2">
<input type="submit" class="btn btn-default" value="Lets Party!" />
</div>
</div>
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
我的问题是,由于其他值(名字,姓氏,电子邮件,出生日期)没有明确地使用@Html.EditorFor(...)
形式的基团内,则设定model
传递给方法ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
在值设置为null
时无效。我对HTML和MVC 5相当陌生,我不知道如何自动将Model
的值传递给model
而不创建自动生成的Html表单。我想这个解决方案很简单,但我无法弄清楚。我希望新用户选择一个ProfileCake
,但其他一切都会自动传递。