0
"코드"및 "설명"필드가 포함 된 전문 기술이라는 테이블이 있습니다.이 테이블에는 약 20 개의 행이 있습니다.CheckBox MVC3에서 데이터베이스 액세스
전문가 표의 설명이있는 체크 박스를 원하는대로 선택하여 버튼을 제출하면 전문 지식 테이블에서 '코드'를 가져 와서 게시해야합니다. 데이터 베이스.
어떻게하면됩니까? 누군가가 나에게 내 모델에서
MVC3
에서이 작업을 수행하는 단계 방법에 의해 단계를 줄 수있다, 나는 다음과 같은 한 : 내 컨트롤러에서public class RegisterModel
{
[StringLength(20, ErrorMessage = "{0} must be at least {2} characters long and a maximum of {1} characters with no spaces.", MinimumLength = 6)]
[Required]
[Display(Name = "User name")]
public string UserName { get; set; }
[Required]
[DataType(DataType.EmailAddress)]
[Display(Name = "Email address")]
public string Email { get; set; }
[Required]
[StringLength(20, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
[Display(Name = "UserPhone")]
public string userPhone { get; set; }
public class ExpertiseModel
{
public string expertiseCode { get; set; }
public string expertiseDesc { get; set; }
}
public class UserExpertiseModel
{
public string expertiseCode { get; set; }
public string otherExpertise { get; set; }
}
public class RegisterSPModel
{
UserExpertiseModel userexpertisemodel;
RegisterModel registermodel;
public RegisterSPModel()
{
userexpertisemodel = new UserExpertiseModel();
registermodel = new RegisterModel();
}
}
를 내가 가지고 :
// GET: /Account/RegisterSP
public ActionResult RegisterSP()
{
DBController dbcontroller = new DBController();
if (dbcontroller.DBConnection())
{
MySqlCommand command = new MySqlCommand("view_all_expertise;", dbcontroller.conn);
command.CommandType = System.Data.CommandType.StoredProcedure;
command.Parameters.Add(new MySqlParameter("expertiseCode", MySqlDbType.String));
command.Parameters["@expertiseCode"].Direction = System.Data.ParameterDirection.Output;
command.Parameters.Add(new MySqlParameter("expertiseDesc", MySqlDbType.String));
command.Parameters["@expertiseDesc"].Direction = System.Data.ParameterDirection.Output;
try
{
MySqlDataReader rdr = command.ExecuteReader();
var expmodel = new ExpertiseModel();
while (rdr.Read())
{
expmodel.expertiseCode = rdr["expertiseCode"].ToString();
expmodel.expertiseDesc = rdr["expertiseDesc"].ToString();
}
ViewBag.Expertise = expmodel;
return View();
}
그리고 내 내가 이것을 가지고 VIEW : @model mvc1.Models.RegisterSPModel
@{
ViewBag.Title = "RegisterSP";
}
@using (Html.BeginForm()) {
<p>
Use the form below to continue creating a new account.
</p>
<div>
<fieldset style = "width: 840px; margin: 0px auto;">
<legend>Account Information - Service Provider</legend>
<br />
@foreach (var item in ViewBag.Expertise)
{
<div>
<table>
<tr>
<td>
<input type="checkbox" name="codes" value="@item.Expertise.expertiseDesc" />
</td>
</tr>
</table>
</div>
}
이 나던 작품 .. VIEW()에서 RegisterSPModel 데이터 필드를 가져올 수 없습니다. VIEW()의 시작 부분에 지정된 경우에도 마찬가지입니다.