我正在尝试将用户的所有信息放入带有表单的视图中以编辑用户信息。我有这个控制器动作:
'
' GET: /Account/EditRegistry/5
Public Function EditRegistry(Optional id As String = Nothing) As ActionResult
' get user model
Dim model = Membership.GetUser(id)
' pass username to view
ViewData("UserName") = id
Return View(model)
End Function
而且,我正在使用这个视图:
@ModelType MyBlog.RegisterModel
@Code
ViewData("Title") = "Register"
End Code
<h2>Create a New Account</h2>
<p>
Use the form below to create a new account.
</p>
<p>
Passwords are required to be a minimum of @Membership.MinRequiredPasswordLength characters in length.
</p>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@Using Html.BeginForm()
@Html.ValidationSummary(True, "Account creation was unsuccessful. Please correct the errors and try again.")
@<div>
<fieldset>
<legend>Account Information</legend>
@Html.Hidden("m.UserName", ViewData("UserName"))
<div class="editor-label">
@Html.LabelFor(Function(m) m.Email)
</div>
<div class="editor-field">
@Html.TextBoxFor(Function(m) m.Email)
@Html.ValidationMessageFor(Function(m) m.Email)
</div>
<div class="editor-label">
@Html.LabelFor(Function(m) m.Password)
</div>
<div class="editor-field">
@Html.PasswordFor(Function(m) m.Password)
@Html.ValidationMessageFor(Function(m) m.Password)
</div>
<div class="editor-label">
@Html.LabelFor(Function(m) m.ConfirmPassword)
</div>
<div class="editor-field">
@Html.PasswordFor(Function(m) m.ConfirmPassword)
@Html.ValidationMessageFor(Function(m) m.ConfirmPassword)
</div>
<div class="editor-label">
@Html.LabelFor(Function(m) m.Company, "Companies")
</div>
<div class="editor-field">
@Html.DropDownList("Company", String.Empty)
@Html.ValidationMessageFor(Function(m) m.Company)
</div>
<div class="editor-label">
@Html.LabelFor(Function(m) m.IsCompanyOwner, "Company Owner?")
</div>
<div class="editor-field">
@Html.CheckBoxFor(Function(m) m.IsCompanyOwner)
@Html.ValidationMessageFor(Function(m) m.IsCompanyOwner)
</div>
<div class="editor-label">
@Html.LabelFor(Function(m) m.Blog, "Blogs")
</div>
<div class="editor-field">
@Html.DropDownList("Blog", String.Empty)
@Html.ValidationMessageFor(Function(m) m.Blog)
</div>
<div class="editor-label">
@Html.LabelFor(Function(m) m.IsBlogOwner, "Blog Owner?")
</div>
<div class="editor-field">
@Html.CheckBoxFor(Function(m) m.IsBlogOwner)
@Html.ValidationMessageFor(Function(m) m.IsBlogOwner)
</div>
<p>
<input type="submit" value="Register" />
</p>
</fieldset>
</div>
End Using
我得到的错误是:
传递到字典中的模型项的类型为“System.Web.Security.MembershipUser”,但此字典需要“MyBlog.RegisterModel”类型的模型项。
如何解决此错误并将用户信息输入模型和视图中的表单?