I am new to MVC, and as I get more involved in the whole structure, I find that model lines are becoming tough to maintain.
Let me explain ...
I am writing a basic CRUD-over-database application. My domain models will be very rich. Trying to limit my controllers as much as possible, I configured them so that in the Create / Edit commands the parameter for the action was a richly populated instance of my domain model. To do this, I implemented a custom connectivity device.
As a result, however, this custom communication device is very specific to presentation and model. I decided to just override the DefaultModelBinder that comes with MVC 2. In the case where the field attached to my model is just a text field (or something simple), I just delegate the base method. However, when I work with a drop-down list or something more complex (the user interface determines that the date and time are separate data entry fields, but for the model this is one property), I have to perform some checks and some manual data manipulations.
The end result of this is that I have a pretty close relationship between View and Binder. I am from an architectural point of view with this, but from a code maintenance point of view, this is a nightmare.
, , , Log ( , Action). "ServiceStateTime" . "log.ServiceStartDate" "log.ServiceStartTime" (Html.TextBox( "log.ServiceStartTime" ,...))
protected override object GetPropertyValue(ControllerContext controllerContext,
ModelBindingContext bindingContext,
PropertyDescriptor propertyDescriptor,
IModelBinder propertyBinder)
{
if (propertyDescriptor.Name == "ServiceStartTime")
{
string date = bindingContext.ValueProvider.GetValue("log.ServiceStartDate").ConvertTo(typeof (string)) as string;
string time =
bindingContext.ValueProvider.GetValue("log.ServiceStartTime").ConvertTo(typeof (string)) as string;
DateTime dateTime = DateTime.Parse(date + " " + time);
return dateTime;
}
if (propertyDescriptor.Name == "ServiceEndTime")
{
string date = bindingContext.ValueProvider.GetValue("log.ServiceEndDate").ConvertTo(typeof(string)) as string;
string time =
bindingContext.ValueProvider.GetValue("log.ServiceEndTime").ConvertTo(typeof(string)) as string;
DateTime dateTime = DateTime.Parse(date + " " + time);
return dateTime;
}
Log.ServiceEndTime - .
. -, ServiceStartTime ServiceEndTime , ( , R #, , ). -, "log.ServiceStartDate" "log.ServiceStartTime" , . - .
, , , , :
- , , , ViewModel, aspx/ascx. ViewModel.
- . , , .
, Fluent NHibernate. , .
, !