I am trying to validate the form on client side(using jQuery) as well as on server side. It works fine on client side but server side validation is not working.
My model is:
public class CustomModel
{
public int Id { get; set; }
[Required]
public string Type { get; set; }
[Required]
public string Amount { get; set; }
[Required]
public string Time { get; set; }
public string Gender { get; set; }
[Required]
public string FirstName { get; set; }
[Required]
public string LastName { get; set; }
}
Controller:
public class CustomSurfaceController : SurfaceController
{
[HttpPost]
[ValidateAntiForgeryToken]
public void Index(CustomModel model)
{
var db = ApplicationContext.Current.DatabaseContext.Database;
if (ModelState.IsValid)
{
//code
}
}
}
Server side form validation in umbraco+mvc
Hi,
I am trying to validate the form on client side(using jQuery) as well as on server side. It works fine on client side but server side validation is not working.
My model is:
Controller:
View Page:
What should I have to do? So, that server side validation also works.
Thanks in advance.
Hi Sabin,
You need to add validation extensions to your view. For example:
You should also consider adding JavaScript unobtrusive settings to your application as well. Take a look at this Nuget package
is working on a reply...