将可编辑字段添加到ASP.NET MVC帐户模型

时间:2013-07-07 02:51:34

标签: c# asp.net-mvc

我无法编辑我在asp.net MVC的帐户模型中添加到我的帐户模型的字段。我可以很好地创建和访问这个字段,但我不能为我的生活弄清楚如何编辑它。我想要编辑的值是“UserInputTwo”

以下是我的模型现在的样子:

[Table("UserProfile")]
public class UserProfile
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public int UserId { get; set; }
    public string UserName { get; set; }
    public string FID { get; set; }
    public string UserInputTwo { get; set; }
}

这是我迄今为止的尝试,但没有运气:

@using (Html.BeginForm("Manage", "Account")) {
    @Html.AntiForgeryToken()
    @Html.ValidationSummary()

    <fieldset>
        <legend>Change Info Form</legend>
        <ol>
            <li>
                @Html.LabelFor(m => m.UserInputTwo)
                @Html.TextBoxFor(m => m.UserInputTwo)
            </li>
        </ol>
        <input type="submit" value="Change password" />
    </fieldset>
}

编辑:这是控制器:

    public ActionResult EditInfo(string user)
    {
        ViewBag.User = user;
            return View();
    }


     [HttpPost]
    public ActionResult EditInfo(UserProfile UserProfile)
    {
        if (ModelState.IsValid)
        {
            db.Entry(UserProfile).State = EntityState.Modified;
            db.SaveChanges();
            return RedirectToAction("Success");
        }
        return RedirectToAction("Success");
    }

0 个答案:

没有答案