1

Question: Are there any Mvc framework solutions that I can leverage to create a clean and concise approach that represents my user control that I am converting? (There are four major design considerations listed below)

  1. This user control has a lot of explanatory text information within. I really want to avoid writing a helper method that is a mile long containing a ton of standard HTML and text.
  2. This user control contains a Grid. I have written my on Grid control in Mvc but I have not had any experience as of yet with composition of html helpers in a clean fashion.
  3. This control is only presented to the user as a result of uploading a spreadsheet for importing purposes.
  4. The design needs to account for being in a standalone dll that is used in other projects.

I was considering the idea of using a Partial View. This would be preferable since it could make calls to the html helper to render my grid and contain the explanatory text.

However, I couldn't find examples online that really lent themselves to my scenario. So I not confident of the details.

Thanks for input in advance.

Matthew Cox
  • 13,566
  • 9
  • 54
  • 72

1 Answers1

0
  1. Explanatory text can be stored in a view model. It'll be stored in a single place and it can easily point to a resource file with localization (if needed)
  2. Re-factoring. I can't get into more details as I haven't seen the code
  3. If you opt-in for a partial view, you can render control with @Html.RenderPartial, @Html.EditorFor, @Html.DisplayFor depending on what kind of control this is. In my project I have controls for storing and displaying search criteria. So I have something on the lines of @Html.EditorFor(model => model.CategorySearch, "CategorySearch")
  4. I'm not sure about a seperate DLL, but if you have a clear seperation between a view and domain model, then you should be able to get away with copying your view model and view related components (e.g. partial view, editor/display templates etc)

I hope this helps

  • Your fourth point isn't negotiable with my boss and rightly so. We have a lot of apps that would use this dll. Once we begin converting some of the other major apps to mvc there will be more controls that fit into this scenario and then we would be in copy/paste frenzy mode whenever we makes changes to the Dll. – Matthew Cox Oct 12 '11 at 17:21
  • I discovered that Mvc uses VirtualPathProviders which would allow me to embed the partial views as embedded resources to circumvent the copy/paste issue. But there is a lot of implementation details and so far not a lot of concrete examples. – Matthew Cox Oct 12 '11 at 17:22
  • I have been a developer for a year or so, so there might well be a way to encapsulate and re-use the control in a different way, I might just not be aware of it. –  Oct 12 '11 at 17:25
  • I am in the exact same boat ... but when you shine, they expect more. =P So I guess it is back to the hunt – Matthew Cox Oct 12 '11 at 17:28
  • I figured out a solution for embedding partial views into a dll. Figured I would share with you and others what I found because this is really really useful stuff for redistribution/maintainability's sake as well as making controls that exist across different domain names. This question covers it http://stackoverflow.com/questions/7746253/using-custom-virtualpathprovider-to-load-embedded-resource-partial-views/7746510#7746510 – Matthew Cox Oct 12 '11 at 21:56