这是一个修改个人信息页面提交表单时报的错。
View代码:
<ul>
<li>
<span> * 省 份:</span>
@Html.DropDownListFor(m => m.Province, (IEnumerable<SelectListItem>)ViewBag.ProvList, new { @class = "DropList", id = "Province", onchange = "ProvinceChang()" })
<span class="Info_Label">@ViewBag.Province</span>
<span> * 市:</span>
@Html.DropDownListFor(m => m.City, ViewBag.CityList as IEnumerable<SelectListItem>, new { @class = "DropList", id = "City", onchange = "CityChang()" })
<span class="Info_Label">@ViewBag.City</span>
<span> * 区/县:</span>
@Html.DropDownListFor(m => m.Area, ViewBag.AreaList as IEnumerable<SelectListItem>, new { @class = "DropList", id = "Area" })
<span class="Info_Label">@ViewBag.Area</span>
</li>
</ul>
控制器:
Get 方法:
List<SelectListItem> ieseProv = new List<SelectListItem>();
List<SelectListItem> ieseCity = new List<SelectListItem>();
List<SelectListItem> ieseArea = new List<SelectListItem>();
ieseProv = he.GetProItem(nuserid);//根据id得到所在省
ieseCity = he.GetCityItem(nuserid);//根据id得到所在市
ieseArea = he.GetAreaItem(nuserid);//根据id得到所在县
if (ieseProv==null||ieseProv.Count<=0)
{
Response.Write("<script>alert('" + ieseProv.Count .ToString()+ "')</script>");
}
ViewBag.ProvList = ieseProv;
ViewBag.CityList = ieseCity;
ViewBag.AreaList = ieseArea;
return View();
POST 方法:
if (string.IsNullOrEmpty(model.UserName) == false && string.IsNullOrEmpty(model.PassWord) == false &&
string.IsNullOrEmpty(model.Address) == false && string.IsNullOrEmpty(model.Area) == false &&
string.IsNullOrEmpty(model.Business) == false && string.IsNullOrEmpty(model.City) == false &&
string.IsNullOrEmpty(model.MobelPhone) == false && string.IsNullOrEmpty(model.People) == false &&
string.IsNullOrEmpty(model.Province) == false && string.IsNullOrEmpty(model.Tel) == false)
{
string strName = model.UserName, strPassWord = model.PassWord, strAddress = model.Address, strArea = model.Area, strBusiness = model.Business, strCity = model.City, strMobelPhone = model.MobelPhone, strPeople = model.People, strProvince = model.Province, strTel = model.Tel;
strProvince = SQLHELP.GetOne("select provincename from province where provinceid='" + strProvince + "'");
strCity = SQLHELP.GetOne("select cityname from city where cityid='" + strCity + "'");
strArea = SQLHELP.GetOne("select areaname from area where areaid='" + strArea + "'");
ArrayList al = new ArrayList() { strBusiness, strPeople, strTel, strMobelPhone,strProvince, strCity, strArea, strAddress, strName, strPassWord };
IDataParameter[] pare = new IDataParameter[] {
new SqlParameter("Business",SqlDbType.Char,50),
new SqlParameter("People",SqlDbType.Char,6),
new SqlParameter("Tel",SqlDbType.Char,11),
new SqlParameter("MobelPhone",SqlDbType.Char,11),
new SqlParameter("Province",SqlDbType.Char,20),
new SqlParameter("City",SqlDbType.Char,20),
new SqlParameter("@Area",SqlDbType.Char,20),
new SqlParameter("@Address",SqlDbType.Char,50),
new SqlParameter("@Name",SqlDbType.Char,30),
new SqlParameter("@PassWord",SqlDbType.Char,30)};
bool IsRegiest = SQLHELP.InsertAll("InsertMberAndLog", pare, al);
而与之结构相同的注册页面提交就不会报这个错!
我在百度上查过,有很多都说是因为selectlistitem里没有值,但是我里确实是有值的啊;或者是我没明白是提交的时候没有值还是页面加载的时候没有值。
请教各位大神这个错误的原因是什么。谢谢了