//例9 public ActionResult Example9(MyStudentModel student) { if (Request.HttpMethod == "GET") { student = new MyStudentModel { XueHao = "001", XingMing = "刘会敏", XingBie = "女", NianLing = 21 }; return(PartialView(student)); } else { string s = "输入有错!"; if (ModelState.IsValid) { s = string.Format( "提交结果:学号:{0},姓名:{1},性别:{2},年龄:{3}", student.XueHao, student.XingMing, student.XingBie, student.NianLing); } return(JavaScript(string.Format("alert('{0}')", s))); } }
//例13 public ActionResult Validation1(MyStudentModel student) { if (Request.HttpMethod == "GET") { student = new MyStudentModel { XueHao = "01", XingMing = "张", NianLing = 3 }; return(PartialView(student)); } else { return(JavaScript("alert('数据已提交!')")); } }
public ViewModel() { AddCommand = new RelayCommand( e => { if (StudentInput != null) { MyStudentModel.Add(new Student { Name = StudentInput.Name, Score = StudentInput.Score }); Console.WriteLine("Student added"); } }, c => { if (StudentInput.Name != "" && StudentInput.Score >= 0 && StudentInput.Score <= 100) { return(true); } else { return(false); } } ); RemoveCommand = new RelayCommand( e => { if (SelectedStudent != null) { MyStudentModel.Remove(SelectedStudent); Console.WriteLine("Student removed"); } }, c => SelectedStudent != null ); }