2
클라이언트 측 유효성 검사를 사용하고 있으며 폼을 작성하고 있다고 생각하면 지저분 해지기 시작합니다. 모든 텍스트 상자 및 라디오 버튼 유효성 검사를 사용하면 컨트롤러가 압도됩니다. 어떻게 확인하고 MODEL 쪽에서 MVC의 라디오 버튼과 여러 텍스트 상자에 대한 오류 메시지를 표시합니까?MVC에서 RadioButton의 유효성을 검사하려면 어떻게합니까?
내가 가지고있는 것의 단순화 된 버전.
모델 ...
public class ModelData
{
public string ContactName { get; set; }
public string ContactAddress { get; set; }
public string ContactPhone { get; set; }
public bool RadioPoliceFire { get; set; }
public bool RadioComplaint { get; set; }
//The following is a Failure :(
public string RadioType
{
if (RadioType == null)
{return "Type Required";}
return null;
}
//End Failure
}
CONTROLLER ...
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Info(ModelData InfoData)
{
if (infoData.RadioType == null)
{ModelState.AddModelError("RadioType", "Type Required");}
try
{ ...
return RedirectToAction("Confirmation");
catch
{ModelState.AddModelError("RadioComplaint", "Error");}
}
이것은 완료 될 것입니다 !!! 내가 MVC 2를 가지고 있다면 ... MVC 2로 업데이트 할 때 이것을 명심해야한다. – MrM