0

I don't want to check StudentID. I just want only StudentName validation. But when I am running the code it is showing me the validation of both properties.How can I solve this problem

public class Student
{
    public int StudentID { get; set; }
    [Required]
    public string StudentName { get; set; }
}

Controller Code:

[HttpPost]
    public ActionResult Crud(Student student)
    {
        if(ModelState.IsValid)
        {
            return RedirectToAction("Crud");
        }
        return View();
    }

View Page Code:

@using (Ajax.BeginForm("Crud", "Students", new AjaxOptions
{ HttpMethod = "POST" }))
{
@Html.ValidationSummary()
<div>
    @Html.LabelFor(x => x.StudentID)<br />
    @Html.EditorFor(x => x.StudentID)
</div><br />
<div>
    @Html.LabelFor(x => x.StudentName)<br />
    @Html.EditorFor(x => x.StudentName)
</div><br />
<input type="submit" value="SAVE" />
}

Output: Both validation are showing here. But I want only StudentName validation

0 Answers0