ASP.NET MVC3 注册用户的问题。
Action:
- C# code
public ActionResult Register() { if (Session["userid"] != null) { ViewBag.Error = "你已经登陆"; return RedirectToAction("Index", "Home"); } else { return View(); } } [HttpPost] public ActionResult Register(FormCollection RegUser) { var model = new Blog.Models.User() { UserName = RegUser["UserName"].ToLower().Trim(), Email = RegUser["Email"].ToLower().Trim(), Password = RegUser["Password"].toMD5(), QQ = RegUser["QQ"].Trim(), RegTime = DateTime.Now, LastLoginTime = DateTime.Now, RegIP = Request.UserHostAddress, LastLoginIP = Request.UserHostAddress, RoleID = 1 }; var dal = new BlogEnt(); dal.Users.Add(model); dal.SaveChanges(); int id = model.UserID; Session["userid"] = id; return RedirectToAction("Index", "Home"); } #endregionVIEW:
- C# code
@using (Html.BeginForm()) { @Html.ValidationSummary(true) <h2>注册用户</h2> <div class="editor-label"> @Html.LabelFor(model => model.UserName) </div> <div class="editor-field"> @Html.EditorFor(model => model.UserName)<span>*必填.用于在网站中显示名称</span> @Html.ValidationMessageFor(model => model.UserName) </div> <div class="editor-label"> @Html.LabelFor(model => model.Email) </div> <div class="editor-field"> @Html.EditorFor(model => model.Email)<span>*用于登陆网站和找回密码</span> @Html.ValidationMessageFor(model => model.Email) </div> <div class="editor-label"> @Html.LabelFor(model => model.Password) </div> <div class="editor-field"> @Html.EditorFor(model => model.Password)<span>*</span> @Html.ValidationMessageFor(model => model.Password) </div> <p> <input type="submit" value="提交注册" /> </p>}原先是这样可以注册的,但是最近不知道什么地方出了问题,就不能注册了。就一直报这个错误:未将对象引用到实例。
如图
可是这个地方,断点又不好调试。
[解决办法]
断点,肯定可以设的吧.
只是方法调试的问题了.
上面的出错,UserName这个可能不存在引起的.
[解决办法]
- C# code
var model = new Blog.Models.User();model.UserName=...