나는 학생 표를 가지고 있으며 students 테이블에 저장된 프로필 페이지에 학생의 이름을 표시하고 싶습니다. 내가 가진 내보기에SQL 데이터베이스에서 텍스트 필드로 데이터 가져 오기
public ActionResult StudentName(StudentModel model)
{
if(ModelState.IsValid)
{
using (var db = new SchoolDataContext())
{
var result = from s in db.Students select s.StudentName;
model.StudentName = result.ToString();
}
}
}
:
이
내가 내 컨트롤러에 대해 생각하고있는 것입니다@Html.LabelFor(s => s.StudentName)
@Html.TextBoxFor(s => s.StudentName)
내 모델 : 나는 GET 필요합니다
public class StudentModel
{
[Display(Name = "Student Name")]
public string StudentName{ get; set; }
}
메서드를 사용하여 학생 이름을 텍스트 상자에 표시하고 동시에 post 메서드를 사용하여 텍스트 상자 내에서 변경된 경우 저장할 수 있습니다. 저장을 클릭 한 후 동일한 상자. 위 얻을, 당신이 ID를 전달하고 데이터베이스에서 레코드를 가져올 수에서
public ActionResult StudentName(int studentId)//you can't pass a model object to a get request
{
var model = new StudentModel();
using (var db = new SchoolDataContext())
{
//fetch your record based on id param here. This is just a sample...
var result = from s in db.Students
where s.id equals studentId
select s.StudentName.FirstOrDefault();
model.StudentName = result.ToString();
}
return View(model);
}
:
난 내가 내 컨트롤러에 무엇을 위해 쓰기 여부를하고 있는지 알고 싶어 –
마흔 두 @ 여기에 질문이 표시되지 않습니다. – 072et