[RESOLVED]how to put validation server side for partial view using AJAX.begin form in mvc Razor ?

how to put validation server side for partial view using AJAX.begin form in mvc Razor

@Models.Student
@using (Ajax.BeginForm("Actionname", new AjaxOptions { }))
{
    <div class="form-group">
        @Html.LabelFor(m => m.Name, new { @class = "col-md-2 control-label" })
        <div class="col-md-10">
            @Html.TextBoxFor(m => m.Name, new { @class = "form-control" })
        </div>
    </div>
    <div class="form-group">
        @Html.LabelFor(m => m.Age, new { @class = "col-md-2 control-label" })
        <div class="col-md-10">
            @Html.TextBoxFor(m => m.Age, new { @class = "form-control" })
        </div>
    </div>
    <input id="Submit1" type="submit" value="Save" />
}

If above is the partial view, following is the checking if model is valid

public ActionResult ActionName(Student studentObject)
{
    if (ModelState.IsValid)
    {
        //do save
        //return appropriate view
    }
    else
        return View();//return view with model error
}

Leave a Reply