1

i've an asp.net mvc project that i used ef. its "Add" controller =>

    [Authorize(Roles = "Admin")]
    public ActionResult Add()
    {
        using (Process _process = new Process())
            ViewBag.KlinikListesi = _process.KlinikleriGetir();
        return View();
    }

    [Authorize(Roles = "Admin")]
    [HttpPost]
    public ActionResult Add(uzmanlik_egitim _ueModel)
    {
        using (Process _process = new Process())
        {

            ViewBag.KlinikListesi = _process.KlinikleriGetir();
            if (Request.QueryString["userName"] != null)
            {
                _ueModel.kullanici_adi = Request.QueryString["userName"].ToString();
                _process.Add(_ueModel);
            }
        }
        return View();
    }

And i created View (selected model as ef table(uzmanlik_egitim))

it works perfectly.

But i need to validate fields, i tried =>

     //[MetadataType(typeof(uzmanlik_egitim_metadata))]
//public partial class uzmanlik_egitim
//{

//}

//public class uzmanlik_egitim_metadata
//{
//    [Required]
//    public string kullanici_adi { get; set; }

//    [Required]
//    public int ID { get; set; }

//    [Required]
//    public string klinik { get; set; }

//    [StringLength(1, ErrorMessage = "En Fazla 1 Karakter")]
//    public int? ulusal_kongre { get; set; }

//    [StringLength(1, ErrorMessage = "En Fazla 1 Karakter")]
//    public int? uluslararasi_kongre { get; set; }

//    [StringLength(1, ErrorMessage = "En Fazla 1 Karakter")]
//    public int? yurtici_sunum { get; set; }

//    [StringLength(1, ErrorMessage = "En Fazla 1 Karakter")]
//    public int? yurtdisi_sunum { get; set; }

//    [StringLength(1, ErrorMessage = "En Fazla 1 Karakter")]
//    public int? yurtici_bilimsel_yayin { get; set; }

//    [StringLength(1, ErrorMessage = "En Fazla 1 Karakter")]
//    public int? yurtdisi_bilimsel_yayin { get; set; }
//}

but i'm getting error because of type i'm stucked.

1 Answer 1

1

I think RangeAttribute is more appropriate here because you are using int as property type.

[Range(0, 9, ErrorMessage = "En Fazla 1 Karakter")]
public int? ulusal_kongre { get; set; }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.