Hi yolo47,
Yes it is possible.
Check this example. Now please take its reference and correct your code.
Model
public class EmployeeModel
{
[Required]
public string Name { get; set; }
[Required]
public string City { get; set; }
[Required]
public string Country { get; set; }
}
Controller
public class HomeController : Controller
{
// GET: /Home/
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Save(EmployeeModel model)
{
// Ignore City from ModelState.
ModelState.Remove("City");
if (ModelState.IsValid)
{
// Do the task
}
else
{
// Do the task
}
return View("Index");
}
}
View
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<_Ignore_Property_ModalStateIsValid.Models.EmployeeModel>" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Index</title>
</head>
<body>
<% using (Html.BeginForm("Save", "Home", FormMethod.Post))
{%>
Name:
<%:Html.TextBoxFor(m=>m.Name) %>
<br />
City:
<%:Html.TextBoxFor(m=>m.City) %>
<br />
Country:<%:Html.TextBoxFor(m=>m.Country) %>
<br />
<input type="submit" value="Save" />
<% } %>
</body>
</html>