我在编写将文本字段框信息保存到数据库中的代码时遇到问题,这就是我所拥有的 - 一个 Get 和 Post 方法:
public ActionResult _UserName(UserNameModel userNameModel)
{
using (var db = new DataConnection())
{
userNameModel.UserName= (from u in db.Users
where u.ID == WebSecurity.CurrentUserId
select u.UserName).FirstOrDefault();
}
return View(userNameModel);
}
}
[HttpPost]
public ActionResult _CreateUserName(string username, UserNameModel userNameModel)
{
if (ModelState.IsValid)
{
using (var db = new DataConnection())
{
try
{
// Need to save what has been entered in the textbox
// to the Users table in the database.
}
catch (Exception)
{
throw;
}
}
return RedirectToAction("UserNamePage");
}
return View(userNameModel);
}