design question - why is logic in the Model?

Jan 18, 2013 at 9:15 PM

hi,

I am new to ASP.NET MVC and need to create a page completely dynamically that will be defined somewhere else. I am using your code as a guide and am curious -

 

  • why is there logic in the Model at all ? (Form class) Why not make HTML a property of the model and have the controller do all the logic?
  • why does the view not do any logic on generating html? couldn't you have made some the loop inside RenderHtml() live inside a Partial View, and then have the View do this logic of looping through each control and feeding it into the view?

Since I am very new to ASP.NET MVC, and have never even done a dynamically generated form site before, I am curious to know why it is like this. It seems that the MVC pattern should have a very dumb model, and a view which decides how to render things?

 

thanks,

 

Drew

Coordinator
Jan 18, 2013 at 9:17 PM

IDK it all seemed like a good idea at the time :)

Jan 20, 2013 at 11:11 PM

Thanks... I am trying to use your example as a guide to developing my own project.. would you have done it the same way if you could do it over again? Or maybe should the View be doing some logic? I'm thinking it might be easier to take advantage of 3rd party ASP.NET MVC extensions (like Telerik or DevExpress) if the view is a little bit intelligent... but I do think it's very slick and there's advantages of the model/controller generated all HTML..

 

Drew

Coordinator
Jan 21, 2013 at 1:12 AM

I think the architecture is mostly just fine. This project provides you with a high level API that lets you define your form fields without worrying how they get rendered too much.

If I wanted to rewrite the software, I probably would make use of things like editor templates and Templated Razor Delegates. But, those features weren't around when I created this project, so I don't feel too bad about it.

If the problem your app solves is allowing for the storage of form fields that get rendered dynamically, there's nothing wrong with your model code being concerned with the view to some degree. I mean if that's what the app is all about, then it's going to be part of the back end code

Jan 22, 2013 at 8:10 PM

I see.. I suppose my worry is not being able to easily use Html helper, and other things like maybe 3rd party MVC extensions. As of now, the View doesn't actually create any HTML (it's all done in the Form).. but how would I be able to integrate MVC extensions and HTML helpers?

 

thanks!

Coordinator
Jan 22, 2013 at 8:31 PM

Could you be more specific about what your trying to do and what you've tried that didn't work?