Another solution would be to create a ViewModel with the attributes that should or should not be written:
namespace MyProject.ViewModels {
public class MyViewModel {
public int Prop1 { get; set; }
[Required]
public String Prop2 { get; set; }
public String Prop3 { get; set; }
public String Prop4 { get; set; }
...
public String Prop12 { get; set; }
}
}
Your View receives, instead of the Model itself, the filled ViewModel:
@model MyProject.ViewModels.MyViewModel
...
Your Controller receives the ViewModel in the POST request and populates a ViewModel in GET:
public ActionResult Create()
{
var viewModel = new MyViewModel();
return View(viewModel);
}
//
// POST: /Cities/Create
[HttpPost]
public ActionResult Create(MyViewModel viewModel)
{
if (ModelState.IsValid)
{
var model = new Model {
Prop1 = viewModel.Prop1,
Prop2 = viewModel.Prop2,
Prop3 = viewModel.Prop3,
...
Prop12 = viewModel.Prop12
};
context.Models.Add(model);
context.SaveChanges();
return RedirectToAction("Index");
}
return View(viewModel);
}