关于MVC中模型(M)中类的调用问题,求高手
我在Controll中接收从View中提交回来的表单(传回的是一个Model),然后再调用在Model中自定义的一个类下的一个方法(将数据存储到数据库中),数据在从表单提交回来和传入Model都没问题,但在数据库中是不完整的记录.....
大体模型是这样的:
Model中代码:
public class RegisterMember
{
public void AddMember(RegisterModel model)
{
UserProfile userProfile = (UserProfile)UserProfile.Create(model.UserName, true);
userProfile.Appellation = model.Appellation;
userProfile.FirstName = model.FirstName;
userProfile.LastName = model.LastName;
userProfile.BirthDay = DateTime.Parse(model.BirthDay);
userProfile.Telephone = model.Phone_number;
userProfile.Country = model.Country;
userProfile.Address1 = model.Address1;
userProfile.Address2 = model.Address2; //可为空(NULL)
userProfile.Save();
}
}
Controll中代码:
using System;
using System.Web.Mvc;
using System.Web.Security;
using ShSite.Models;
namespace ShSite.Controllers
{
public class AccountController : Controller
{
public ActionResult Register(RegisterModel model)
{
if (ModelState.IsValid)
{
// 尝试注册用户
MembershipCreateStatus createStatus;
MembershipUser mUser = Membership.CreateUser(model.UserName, model.Password, model.Email, true, null, out createStatus);
if (createStatus == MembershipCreateStatus.Success)
{
FormsAuthentication.SetAuthCookie(model.UserName, false/* createPersistentCookie */);
RegisterMember rMember = new RegisterMember();
rMember.AddMember(model);
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError("", ErrorCodeToString(createStatus));
}
}
// 如果我们进行到这一步时某个地方出错,则重新显示表单
return View(model);
}
}
}
------解决方案--------------------
你该看下 数据库字段的长度设置是否够长.