如何修改用户信息? [英] How to modify user info?
问题描述
我已经成功实现了当用户注册到我的asp.net mvc网站时,他们必须填写他们的BirthDate,FullName和Country。现在我正在尝试启用,以便他们可以更改信息。
我在ManageViewModel中的SetCountryViewModel:
public class SetCountryViewModel
{
[Required]
[Display(Name =" Country")]
public string Country {get;组; }
}
SetCountry.cshtml
@model SampleProject.Models.SetCountryViewModel
@ {
ViewBag.Title =" Change Country" ;;
}
< h2> @ ViewBag.Title。< / h2>
< p class =" text-info">
在这里你可以改变你的国家。
< / p>
@using(Html.BeginForm(" SetCountry"," Manage",FormMethod.Post,new {@class =" form-horizontal",role =" form"}))
{
@ Html.AntiForgeryToken()
@ Html.ValidationSummary("",new {@class =" text-danger"})
< div class =" form-group">
@ Html.LabelFor(m => m.Country,new {@class =" col-md-2 control-label"})
< div class =" col-md- 10 QUOT;>
@ Html.TextBoxFor(m => m.Country,new {@class =" form-control"})
< / div>
< / div>
< div class =" form-group">
< div class =" col-md-offset-2 col-md-10">
< input type =" submit"值= QUOT确定]; class =" btn btn-default" />
< / div>
< / div>
}
@section脚本{
@ Scripts.Render("〜/ bundles / jqueryval")
}
这是我有问题的部分我猜
ManageController:
public ActionResult SetCountry ()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public async任务< ActionResult> SetCountry(SetCountryViewModel model)
{
if(!ModelState.IsValid)
{
return RedirectToAction(" SetCountry"," Manage");
}
var user = await User.Identity.GetUserId(model.Country);
if(user!= null)
{
var result = await UserManager.UpdateAsync(user);
if(result.Succeeded)
{
result = await UserManager.UpdateAsync(user);
}
}
返回RedirectToAction(" Index"," Manage");
}
在控制器中使用此代码,我得到"CS1501没有方法重载"GetUserId'取1个参数"我无法弄清楚如何正确地做到这一点,有人可以帮助我吗?我已经在网上搜索了3天而没有到达任何地方!
http://forums.asp.net/1146.aspx/1?MVC
发布到MVC论坛...... 跨度> 跨度>
I have successfully implemented to that when users register to my asp.net mvc site they have to fill out their BirthDate, FullName and Country. Now i am trying to enable so they can change their info.
My SetCountryViewModel in ManageViewModels:
public class SetCountryViewModel { [Required] [Display(Name = "Country")] public string Country { get; set; } }
SetCountry.cshtml
@model SampleProject.Models.SetCountryViewModel @{ ViewBag.Title = "Change Country"; } <h2>@ViewBag.Title.</h2> <p class="text-info"> Here you can change your Country. </p> @using (Html.BeginForm("SetCountry", "Manage", FormMethod.Post, new { @class = "form-horizontal", role = "form" })) { @Html.AntiForgeryToken() @Html.ValidationSummary("", new { @class = "text-danger" }) <div class="form-group"> @Html.LabelFor(m => m.Country, new { @class = "col-md-2 control-label" }) <div class="col-md-10"> @Html.TextBoxFor(m => m.Country, new { @class = "form-control" }) </div> </div> <div class="form-group"> <div class="col-md-offset-2 col-md-10"> <input type="submit" value="OK" class="btn btn-default" /> </div> </div> } @section Scripts { @Scripts.Render("~/bundles/jqueryval") }
This is the part i have problem with i guess
ManageController:
public ActionResult SetCountry() { return View(); } [HttpPost] [ValidateAntiForgeryToken] public async Task<ActionResult> SetCountry(SetCountryViewModel model) { if (!ModelState.IsValid) { return RedirectToAction("SetCountry", "Manage"); } var user = await User.Identity.GetUserId(model.Country); if (user != null) { var result = await UserManager.UpdateAsync(user); if (result.Succeeded) { result = await UserManager.UpdateAsync(user); } } return RedirectToAction("Index", "Manage"); }
With this code in the controller i get "CS1501 no overload for method 'GetUserId' takes 1 argument" i cant figure out how to do it correctly, can someone please help me? i have searched online for 3 days now without getting anywhere!
http://forums.asp.net/1146.aspx/1?MVC
Post to the MVC forum...
这篇关于如何修改用户信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!