0

我在编辑我在 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");
    }
4

0 回答 0