Sample Model
public class State { public int State_Id { get; set; } public string State_Title { get; set; } } public class City { public int City_Id { get; set; } public string City_Title { get; set; } public State state { get; set } }
ASP.NET - MVC
ModelState.SetModelValue("City_Id", new ValueProviderResult("Change City ID", "", CultureInfo.InvariantCulture)); ModelState.SetModelValue("City_Title", new ValueProviderResult("Change Title", "", CultureInfo.InvariantCulture)); ModelState.SetModelValue("state.State_Id", new ValueProviderResult("Change State Id", "", CultureInfo.InvariantCulture)); ModelState.SetModelValue("state.State_Title", new ValueProviderResult("Change Title", "", CultureInfo.InvariantCulture));
ASP.NET - CORE MVC
ModelState.SetModelValue("City_Id", new ValueProviderResult("New Value", CultureInfo.InvariantCulture)); ModelState.SetModelValue("City_Title", new ValueProviderResult("New Value", CultureInfo.InvariantCulture)); ModelState.SetModelValue("state.State_Id", new ValueProviderResult("New Value", CultureInfo.InvariantCulture)); ModelState.SetModelValue("state.State_Title", new ValueProviderResult("New Value", CultureInfo.InvariantCulture));
Clear Or Reset ModelState
ModelState.Clear();
Post Comments(0)